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
datastore-indexes.xml. 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
datastore-indexes.xml 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 a
<?xml version="1.0" encoding="utf-8"?> <datastore-indexes autoGenerate="true"> <datastore-index kind="Employee" ancestor="false"> <property name="lastName" direction="asc" /> <property name="hireDate" direction="desc" /> </datastore-index> <datastore-index kind="Project" ancestor="false"> <property name="dueDate" direction="asc" /> <property name="cost" direction="desc" /> </datastore-index> </datastore-indexes>
<datastore-index> element can contain 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.
Deploying the index configuration fileThe
datastore-indexes.xmlfile should reside in the
your application'sdirectory of the default service.
To deploy the datastore indexes configuration file without otherwise altering the currently serving version, use the command:
appcfg.sh update_indexes <application directory>
<application directory> with the path to your application main
Deleting unused indexes
When you change or remove an index from the index configuration, the original index is not deleted from App Engine automatically. This gives you the opportunity to leave an older version of the app running while new indexes are being built, or to revert to the older version immediately if a problem is discovered with a newer version.
When you are sure that old indexes are no longer needed, you can delete them from App Engine as follows:
./appengine-java-sdk/bin/appcfg.sh vacuum_indexes myapp/war