[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-05 (世界標準時間)。"],[[["\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)."]]