App Engine predefines a simple index on each property of an entity. An App
Engine application can define further custom indexes in an index configuration
index.yaml. The development server can generate the index
configuration needed by your application when it performs these
queries while you are testing your app. You can tune indexes manually by editing
index.yaml file before uploading the application. See
Configuring Datastore Indexes for information about how to deploy
and manage index configurations.
The following is an example of an
indexes: - kind: Cat ancestor: no properties: - name: name - name: age direction: desc - kind: Cat properties: - name: name direction: asc - name: whiskers direction: desc # This pound sign is the syntax for a comment. - kind: Store ancestor: yes properties: - name: business direction: asc - name: owner direction: asc
The syntax of
index.yaml is the YAML
index.yaml file has a single list element called
indexes. Each element
in the list represents an index for the application.
The index items can have the following elements:
||Required. The kind of the entity for the query.|
A list of properties to include as columns of the index, in the order to be sorted: properties used in equality filters first, followed by the property used in inequality filters, then the sort orders and their directions.
Each element in this list has the following elements:
Automatic and manual indexes
Determining the indexes required by your application's queries manually can be
tedious and error-prone. Thankfully, the development server can determine the
index configuration for you. To use automatic index configuration, add the
autoGenerate="true" to your
<datastore-indexes> element. Automatic index configuration is also used if
does not have a
With automatic index configuration enabled, the development server maintains a
WEB-INF/appengine-generated/datastore-indexes-auto.xml in your
war/ directory. When your app, running in
the development server, attempts a datastore query for which
there is no corresponding index in either
datastore-indexes-auto.xml, the server adds the appropriate configuration to
If automatic index configuration is enabled when you upload your application,
appcfg command uses both
datastore-indexes-auto.xml to determine which indexes need to be built for
your app in production.
autoGenerate="false" is in your
datastore-indexes.xml, the development
ignore the contents of
datastore-indexes-auto.xml. If the app
running locally performs a query whose index is not specified in
datastore-indexes.xml, the development server throws an exception, just as
the production Datastore would.
It's a good idea to occasionally move index configuration from
datastore-indexes.xml, then disable automatic
index configuration and test your app in
the development server. This makes
it easy to maintain indexes without having to manage two files, and ensures that
your testing will reproduce errors caused by missing index configuration.