Tester des applications et gérer des index à l'aide de l'outil gcloud
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Vous pouvez utiliser la Google Cloud CLI pour tester votre application localement et gérer les index de votre instance de production Firestore en mode Datastore. Cette page décrit le workflow type permettant de réaliser ces activités.
Gcloud CLI est compatible avec le workflow suivant:
Créez un environnement compatible local pour une instance Datastore, y compris un répertoire ainsi que les fichiers requis et l'ID de projet.
Lancez l'émulateur Datastore, qui fournit une émulation locale de l'environnement Datastore de production.
Générez des définitions d'index à partir des requêtes depuis votre application vers l'émulateur.
Importez des définitions d'index créées ou générées manuellement vers votre instance de base de données de production.
Supprimez les index inutilisés de votre instance de base de données de production.
Processus de développement à l'aide de l'outil de ligne de commande
Voici le workflow type exécuté à l'aide de gcloud CLI:
Démarrez votre application et testez-la par rapport à l'émulateur. Vous devez exécuter les requêtes que votre application utilise sur l'émulateur afin de générer des index pour votre instance de base de données de production.
Importez les index générés à l'aide de la commande indexes create pour transmettre le chemin d'accès au fichier index.yaml local, comme dans l'exemple suivant :
L'exemple de chemin d'accès suppose que vous n'avez pas défini de répertoire spécifique pour l'option data-dir. Si vous avez défini un répertoire spécifique, remplacez le chemin d'accès par celui de votre fichier index.yaml.
Exécutez votre application sur votre instance de base de données de production.
Avec le temps, vous êtes susceptible de ne plus utiliser certains index. Vous pouvez supprimer des index inutilisés de votre instance de base de données de production en les supprimant de votre fichier index.yaml local, puis en exécutant la commande indexes cleanup :
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/08 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/08 (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)."]]