Utilizzo dello strumento gcloud per testare le applicazioni e gestire gli indici
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Puoi utilizzare Google Cloud CLI per testare l'applicazione in locale e per gestire gli indici per l'istanza Firestore in produzione in modalità Datastore. Questa pagina descrive il flusso di lavoro tipico per queste attività.
Gcloud CLI supporta il seguente flusso di lavoro:
Crea il supporto locale per un'istanza Datastore, inclusa la directory, i file richiesti e l'ID progetto.
Avvia l'emulatore Datastore, che fornisce l'emulazione locale dell'ambiente Datastore di produzione.
Genera le definizioni degli indici dalle query dell'applicazione all'emulatore.
Carica le definizioni degli indici create o generate manualmente nell'istanza di database di produzione.
Elimina gli indici inutilizzati dall'istanza di database di produzione.
Il flusso di lavoro di sviluppo utilizzando lo strumento a riga di comando
Di seguito è riportato il flusso di lavoro tipico che utilizza gcloud CLI:
Avvia l'applicazione e testala sull'emulatore. Devi eseguire le query utilizzate dall'applicazione sull'emulatore per generare gli indici per l'istanza del database di produzione.
Carica gli indici generati con il comando indexes create, passando il percorso del file index.yaml locale, come nell'esempio seguente:
Il percorso di esempio presuppone che non sia stata impostata una directory specifica per l'opzione data-dir. Se hai impostato una directory specifica, modifica il percorso in modo da utilizzare il percorso del file index.yaml.
Esegui l'applicazione nell'istanza del database di produzione.
Nel tempo, potresti non utilizzare più alcuni degli indici. Puoi eliminare gli indici inutilizzati dall'istanza del database di produzione rimuovendoli dal file index.yaml locale e poi richiamando il comando indexes cleanup:
Se hai impostato una directory specifica per l'opzione data-dir, modifica il percorso nell'esempio in modo da utilizzare il percorso del file index.yaml.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-05 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)."]]