[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eDatastore utilizes indexes for every query, which are automatically updated when an entity changes to ensure quick results.\u003c/p\u003e\n"],["\u003cp\u003eWhile simple query indexes are created automatically, complex query indexes must be defined in an \u003ccode\u003eindex.yaml\u003c/code\u003e configuration file, which is uploaded with the application.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eindex.yaml\u003c/code\u003e file specifies index properties such as \u003ccode\u003ekind\u003c/code\u003e, \u003ccode\u003eproperties\u003c/code\u003e and \u003ccode\u003eancestor\u003c/code\u003e and can be either manually created or automatically generated using the Datastore emulator.\u003c/p\u003e\n"],["\u003cp\u003eWhen testing locally, the Datastore emulator automatically adds index definitions to the \u003ccode\u003eindex.yaml\u003c/code\u003e file, allowing for efficient index creation during development.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eindex.yaml\u003c/code\u003e file is deployed using either the \u003ccode\u003egcloud app deploy\u003c/code\u003e, \u003ccode\u003emvn appengine:deployIndex\u003c/code\u003e or \u003ccode\u003egradle appengineDeployIndex\u003c/code\u003e commands, or by selecting individual configuration files in IDEs like IntelliJ or Eclipse, and old unused indexes can be deleted with \u003ccode\u003egcloud datastore indexes cleanup\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Configuring Datastore Indexes with index.yaml\n\nYou can use [Firestore in Datastore mode (Datastore)](/appengine/docs/legacy/standard/java/using-cloud-datastore)\nfor storing data for your applications that run in the standard\nenvironment. Datastore uses\n[indexes](/datastore/docs/concepts/indexes)\nfor every query your application makes. These indexes are updated whenever an\nentity changes, so the results can be returned quickly when the app makes a\nquery. To do this, Datastore needs to know in advance which\nqueries the application will make. You specify which indexes your app needs in a\n`index.yaml` configuration file. You can use the Datastore\nemulator to generate the file automatically as you test your app, or write the\nfile yourself. The `index.yaml` file must be uploaded when you deploy your app.\n\nAbout `index.yaml`\n------------------\n\nEvery Datastore query made by an application needs a\ncorresponding index. Indexes for simple queries, such as queries over a single\nproperty, are created automatically. Indexes for complex queries must be defined\nin a configuration file named `index.yaml`. This file is uploaded with the\napplication to create indexes in Datastore.\n\nThe following is an example of an `index.yaml` file: \n\n indexes:\n\n - kind: Cat\n ancestor: no\n properties:\n - name: name\n - name: age\n direction: desc\n\n - kind: Cat\n properties:\n - name: name\n direction: asc\n - name: whiskers\n direction: desc\n\n - kind: Store\n ancestor: yes\n properties:\n - name: business\n direction: asc\n - name: owner\n direction: asc\n\nThe syntax of `index.yaml` is the YAML format. For more information about this\nsyntax, see [the YAML website](http://www.yaml.org/) for more information.\n| **Note:** The YAML format supports comments. A line that begins with a pound (`#`) character is ignored: \n| `# This is a comment.`\n\nIndex definitions\n-----------------\n\n`index.yaml` has a single list element called `indexes`. Each element in the\nlist represents an index for the application.\n\nAn index element can have the following elements:\n\n`kind`\n: The kind of the entity for the query. This element is required.\n\n`properties`\n\n: A list of properties to include as columns of the index, in the order to be\n sorted: properties used in equality filters first, followed by the property used\n in inequality filters, then the sort orders and their directions.\n\n Each element in this list has the following elements:\n\n `name`\n : The datastore name of the property.\n\n `direction`\n : The direction to sort, either `asc` for ascending or `desc` for descending. This is only required for properties used in sort orders of the query, and must match the direction used by the query. The default is `asc`.\n\n`ancestor`\n\n: `yes` if the query has an ancestor clause ([Query.setAncestor](/appengine/docs/legacy/standard/java/datastore/queries#ancestor_queries)). The default is `no`.\n\nCreating index files\n--------------------\n\nYou can create an index file manually, using a text editor and following the\nfile layout described above. A more efficient approach is to automatically\ngenerate the file as you test your app locally. You can combine the two methods.\n\nWhen you are testing in your local environment, you can use the\n[gcloud emulator command](/sdk/gcloud/reference/beta/emulators/datastore/start)\nto start a service that emulates Datastore before you run your\napp: \n\n gcloud beta emulators datastore start --data-dir DATA-DIR\n\nUse the `--data-dir` flag to specify the directory where the auto-generated\n`index.yaml` file will appear.\n\nAs you test your app, each time you generate a Datastore query,\nthe emulator adds a generated index definition to `index.yaml`. All the\nautomatically generated index definitions will appear in the file below the\nfollowing line: \n\n # AUTOGENERATED\n\nAll index definitions above this line are considered to be under manual\ncontrol, and are not updated by the development web server. The web server\nwill only make changes below the line, and will only do so if the complete\n`index.yaml` file does not describe an index that accounts for a query executed\nby the application. To take control of an automatic index definition, move it\nabove this line.\n\nThe emulator may update existing definitions below this line as the application\nmakes queries. If the app generates every query it will make while you test it,\nthen the generated entries in `index.yaml` will be complete. You might need to\nedit the file manually to delete indexes that are not used in production, or to\ndefine indexes that were not created while testing.\n\nDeploying the index configuration file\n--------------------------------------\n\nThe `index.yaml` file can reside anywhere in your source code directory.\n\nTo deploy the file without otherwise altering the currently serving version, use\none of the following commands in the directory containing your index file,\ndepending on your environment: \n\n### gcloud\n\n gcloud app deploy index.yaml\n\n### Maven\n\n mvn appengine:deployIndex index.yaml\n\n### Gradle\n\n gradle appengineDeployIndex index.yaml\n\n### IDE\n\nIf you use [IntelliJ](/tools/intellij/docs/deploy-std) or\n[Eclipse](/eclipse/docs/deploying), you\nselect the individual configuration files to be deployed using the\ndeployment form.\n\nDeleting unused indexes\n-----------------------\n\nWhen you change or remove an index from the index configuration, the original\nindex is not deleted from App Engine automatically. This gives you the\nopportunity to leave an older version of the app running while new indexes are\nbeing built, or to revert to the older version immediately if a problem is\ndiscovered with a newer version.\n\nWhen you are sure that old indexes are no longer needed, you can delete them\nfrom App Engine as follows: \n\n gcloud datastore indexes cleanup index.yaml"]]