[[["易于理解","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 updated upon entity changes to ensure rapid query results, but it requires knowing the queries in advance.\u003c/p\u003e\n"],["\u003cp\u003eComplex queries require index definitions in an \u003ccode\u003eindex.yaml\u003c/code\u003e file, which is uploaded during app deployment, while simple queries are automatically indexed.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eindex.yaml\u003c/code\u003e file can be manually created or automatically generated by the Datastore emulator during local testing, with auto-generated indexes appearing below the \u003ccode\u003e# AUTOGENERATED\u003c/code\u003e line.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egcloud\u003c/code\u003e tool is used to manage indexes, allowing you to deploy the \u003ccode\u003eindex.yaml\u003c/code\u003e file with \u003ccode\u003egcloud app deploy index.yaml\u003c/code\u003e, and clean up unused indexes with \u003ccode\u003egcloud datastore indexes cleanup index.yaml\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe index definitions that can be added to the index.yaml file include the kind, properties, name, direction and ancestor, all of which are utilized in order to sort through properties.\u003c/p\u003e\n"]]],[],null,["# Configure Datastore indexes with index.yaml\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nGo Java Node.js PHP Python Ruby .NET Custom\n\n\nYou can use\n[Firestore in Datastore mode (Datastore)](/appengine/docs/flexible/using-firestore-in-datastore-mode)\nfor storing data for your applications that run in the flexible\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\nSample `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: Required. The kind of the entity for the query.\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\u003cbr /\u003e\n\n`ancestor`\n:\n\nCreate 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\nDeploy the index configuration file\n-----------------------------------\n\n\nTo deploy the `index.yaml` configuration file, run the following command: \n\n gcloud app deploy index.yaml\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nDelete 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\n\n\u003cbr /\u003e"]]