Menggunakan Alat gcloud untuk Menguji Aplikasi dan Mengelola Indeks
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Anda dapat menggunakan Google Cloud CLI untuk menguji aplikasi secara lokal dan mengelola indeks untuk Firestore produksi di instance mode Datastore. Halaman ini
menjelaskan alur kerja umum untuk aktivitas ini.
gcloud CLI mendukung alur kerja berikut:
Buat dukungan lokal untuk instance Datastore, termasuk direktori, file yang diperlukan, dan project ID.
Mulai emulator Datastore, yang menyediakan emulasi lokal
lingkungan Datastore produksi.
Buat definisi indeks dari kueri aplikasi Anda ke emulator.
Upload definisi indeks yang dibuat atau dihasilkan secara manual ke instance database produksi Anda.
Hapus indeks yang tidak digunakan dari instance database produksi Anda.
Alur kerja pengembangan menggunakan alat command line
Berikut adalah alur kerja standar menggunakan gcloud CLI:
Mulai aplikasi Anda dan uji di emulator. Anda perlu menjalankan
kueri yang digunakan aplikasi terhadap emulator untuk membuat indeks
untuk instance database produksi.
Upload indeks yang dihasilkan dengan perintah indexes create, dengan meneruskan
jalur ke file index.yaml lokal Anda, seperti dalam contoh berikut:
Contoh jalur mengasumsikan bahwa Anda belum menetapkan direktori tertentu untuk
opsi data-dir. Jika Anda telah menetapkan direktori tertentu, ubah
jalur untuk menggunakan jalur ke file index.yaml.
Hapus variabel lingkungan agar aplikasi Anda mengetahui bahwa aplikasi tersebut menggunakan instance database produksi.
Jalankan aplikasi Anda terhadap instance database produksi.
Seiring waktu, Anda mungkin tidak lagi menggunakan beberapa indeks. Anda dapat menghapus
indeks yang tidak digunakan dari instance database produksi dengan
menghapusnya dari file index.yaml lokal, lalu memanggil
perintah indexes cleanup:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-19 UTC."],[[["\u003cp\u003eThe Google Cloud CLI can be used to test applications locally and manage indexes for production Firestore in Datastore mode instances.\u003c/p\u003e\n"],["\u003cp\u003eThe typical workflow involves creating local support, starting the Datastore emulator, and generating index definitions from application queries.\u003c/p\u003e\n"],["\u003cp\u003eGenerated or manually created index definitions can be uploaded to the production database instance using the \u003ccode\u003eindexes create\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eUnused indexes can be removed from the production database instance by modifying the local \u003ccode\u003eindex.yaml\u003c/code\u003e file and using the \u003ccode\u003eindexes cleanup\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eSetting and removing environment variables allows the application to switch between using the emulator and the production database instance.\u003c/p\u003e\n"]]],[],null,["# Using the gcloud Tool to Test Applications and Manage Indexes\n\nYou can use the Google Cloud CLI to test your application locally and\nto manage indexes for your production Firestore in Datastore mode instance. This page\ndescribes the typical workflow for these activities.\n| **Note:** This discussion assumes that you have already [enabled](/datastore/docs/activate) the Datastore API for your project; [downloaded](/sdk) the Google Cloud CLI, which contains the gcloud CLI; and set up the gcloud CLI using [`gcloud init`](/sdk/gcloud/reference/init).\n\nThe gcloud CLI supports the following workflow:\n\n1. Create local support for a Datastore instance, including directory, required files, and project ID.\n2. Start up the Datastore emulator, which provides local emulation of the production Datastore environment.\n3. Generate index definitions from your application's queries to the emulator.\n4. Upload manually created or generated index definitions to your production database instance.\n5. Delete unused indexes from your production database instance.\n\nThe development workflow using the command-line tool\n----------------------------------------------------\n\nThe following is the typical workflow using the gcloud CLI:\n\n1. [Start the Datastore emulator](/datastore/docs/tools/datastore-emulator#starting_the_emulator).\n\n2. [Set environment variables](/datastore/docs/tools/datastore-emulator#setting_environment_variables) so your application knows it is using the\n emulator.\n\n3. Start your application and test it against the emulator. You need to run the\n queries your application uses against the emulator in order to generate indexes\n for your production database instance.\n\n4. Upload the generated indexes with the [`indexes create`](/sdk/gcloud/reference/datastore/indexes/create) command, passing\n in the path to your local `index.yaml` file, as in the following example:\n\n gcloud datastore indexes create ~/.config/gcloud/emulators/datastore/WEB-INF/index.yaml\n\n The example path assumes you have not set a specific directory for the\n [`data-dir`](/sdk/gcloud/reference/beta/emulators/datastore/start#FLAGS) option. If you have set a specific directory, modify the\n path to use the path to your `index.yaml` file.\n5. [Remove environment variables](/datastore/docs/tools/datastore-emulator#removing_environment_variables) so your application knows it is using the\n production database instance.\n\n6. Run your application against your production database\n instance.\n\n7. Over time, you might no longer use some of the indexes. You can delete\n unused indexes from your production database instance by\n removing them from your local `index.yaml` file and then invoking the\n [`indexes cleanup`](/sdk/gcloud/reference/datastore/indexes/cleanup) command:\n\n gcloud datastore indexes cleanup ~/.config/gcloud/emulators/datastore/WEB-INF/index.yaml\n\n If you have set a specific directory for the [`data-dir`](/sdk/gcloud/reference/beta/emulators/datastore/start#FLAGS) option, modify the\n path in the example to use the path to your `index.yaml` file.\n\nWhat's next\n-----------\n\n- Learn more about the [emulator](/datastore/docs/tools/datastore-emulator).\n- Get details about [Index configuration](/datastore/docs/tools/indexconfig)."]]