Python 2.7 has reached end of supportand will bedeprecatedon January 31, 2026. After deprecation, you won't be able to deploy Python 2.7applications, even if your organization previously used an organization policy tore-enable deployments of legacy runtimes. Your existing Python2.7 applications will continue to run and receive traffic after theirdeprecation date. We recommend thatyoumigrate to the latest supported version of Python.

Configuring Datastore Indexes with index.yaml

You can useFirestore in Datastore mode (Datastore)for storing data for your applications that run in the standardenvironment. Datastore usesindexes for every query your application makes. These indexes are updated whenever anentity changes, so the results can be returned quickly when the app makes aquery. To do this, Datastore needs to know in advance whichqueries the application will make. You specify which indexes your app needs in aindex.yaml configuration file. You can use the Datastoreemulator to generate the file automatically as you test your app, or write thefile yourself. Theindex.yaml file must be uploaded when you deploy your app.

Aboutindex.yaml

Every Datastore query made by an application needs acorresponding index. Indexes for simple queries, such as queries over a singleproperty, are created automatically. Indexes for complex queries must be definedin a configuration file namedindex.yaml. This file is uploaded with theapplication to create indexes in Datastore.

The following is an example of anindex.yaml file:

indexes:-kind:Catancestor:noproperties:-name:name-name:agedirection:desc-kind:Catproperties:-name:namedirection:asc-name:whiskersdirection:desc-kind:Storeancestor:yesproperties:-name:businessdirection:asc-name:ownerdirection:asc

The syntax ofindex.yaml is the YAML format. For more information about thissyntax, seethe YAML website for more information.

Note: The YAML format supports comments. A line that begins with a pound (#)character is ignored:
# This is a comment.

Index definitions

index.yaml has a single list element calledindexes. Each element in thelist represents an index for the application.

An index element can have the following elements:

kind
The kind of the entity for the query. Typically, thisis the name of theModelclass that defines the model for the entities. This element is required.
properties

A list of properties to include as columns of the index, in the order to besorted: properties used in equality filters first, followed by the property usedin inequality filters, then the sort orders and their directions.

Each element in this list has the following elements:

name
The datastore name of the property.
direction
The direction to sort, eitherasc for ascending ordesc 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 isasc.
ancestor

yes if the query has an ancestor clause (eitherQuery.ancestor() or a GQLANCESTOR IS clause). The default isno.

Creating index files

You can create an index file manually, using a text editor and following thefile layout described above. A more efficient approach is to automaticallygenerate the file as you test your app locally. You can combine the two methods.

When you are testing in your local environment, you can use thegcloud emulator commandto start a service that emulates Datastore before you run yourapp:

gcloudbetaemulatorsdatastorestart--data-dirDATA-DIR

Use the--data-dir flag to specify the directory where the auto-generatedindex.yaml file will appear.

As you test your app, each time you generate a Datastore query,the emulator adds a generated index definition toindex.yaml. All theautomatically generated index definitions will appear in the file below thefollowing line:

# AUTOGENERATED

All index definitions above this line are considered to be under manualcontrol, and are not updated by the development web server. The web serverwill only make changes below the line, and will only do so if the completeindex.yaml file does not describe an index that accounts for a query executedby the application. To take control of an automatic index definition, move itabove this line.

The emulator may update existing definitions below this line as the applicationmakes queries. If the app generates every query it will make while you test it,then the generated entries inindex.yaml will be complete. You might need toedit the file manually to delete indexes that are not used in production, or todefine indexes that were not created while testing.

Deploying the index configuration file

To deploy theindex.yaml configuration file, run the following command:

gcloudappdeployindex.yaml

Deleting unused indexes

When you change or remove an index from the index configuration, the originalindex is not deleted from App Engine automatically. This gives you theopportunity to leave an older version of the app running while new indexes arebeing built, or to revert to the older version immediately if a problem isdiscovered with a newer version.

When you are sure that old indexes are no longer needed, you can delete themfrom App Engine as follows:

gclouddatastoreindexescleanupindex.yaml

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.