1

I would like to have indexes only on few fields in a kind. Rather than excluding all the fields in the in the Java code during the creation of Entity as described here, I was wondering if there is a way I can define it in index.yaml file and not worry about it during creation of entities.

Srik
  • 2,341
  • 2
  • 21
  • 35

1 Answers1

2

App Engine applications written in Java do not have an index.yaml file, they have a datastore-indexes.xml file instead. However, the concept is the same.

By default, most properties are indexed by default. Any composite indexes must be defined in your index config file (yaml or xml depending on language). When defining your models, you can tell App Engine to prevent auto-indexing a property. This will save write-ops and speed up your app.

To answer your question more specifically, you cannot use the index config file to prevent index creation, rather it is used to tell App Engine which indexes to create.

Also, indexes are only created as entities are saved. So if you add more after entities have been crested, you will need to run a script to update them.

Similarly, to remove indexes after they have been created you need to do this from the command line using the sdk. See here.

Gwyn Howell
  • 5,365
  • 2
  • 31
  • 48
  • Gwyn Howell, Thanks for your response. I use App Engine Flexible environment which uses index.yaml (https://cloud.google.com/appengine/docs/flexible/java/configuring-datastore-indexes-with-index-yaml) file. I guess I could have been more specific. – Srik Aug 30 '16 at 16:02
  • "When defining your models, you can tell App Engine to prevent auto-indexing a property". How to do this? – Srik Aug 30 '16 at 16:04
  • 1
    In python you set indexed=False i the property constructor. https://cloud.google.com/appengine/docs/python/datastore/indexes#Python_Unindexed_properties Not sure about Java – Gwyn Howell Aug 30 '16 at 16:10
  • 1
    Ahh - here's the java docs -> https://cloud.google.com/appengine/docs/java/datastore/indexes#Java_Unindexed_properties – Gwyn Howell Aug 30 '16 at 16:10
  • I think that link will not work in `flexible` environment (outside standard App Engine). For flexible environment, I have provided a link in my question which explains how to do it. Basically I have to use `StringValue.Builder`, `ListValue.Builder` etc for every property and then call `excludeFromIndexes` for each of them. I find it very cumbersome code to do a such a simple thing. – Srik Aug 30 '16 at 16:27
  • Sorry, I wasn't aware you were using flexible environment. Out of curiosity, why did you opt for flexible environment over fully managed? – Gwyn Howell Aug 30 '16 at 16:29
  • Fully managed does not support Servlets 3.1 and Java 8. I have an app that uses both. I am migrating it to App Engine. So instead of converting my app to older technologies, I thought of using flexible environment. – Srik Aug 30 '16 at 16:32
  • makes perfect sense! – Gwyn Howell Aug 30 '16 at 16:33