Problem
I experience a "no matching index found" exception when querying a datastore for a property "imdbUrl" and sorting by property "created".
I defined the following entity in GAE-Datastore:
// Create a Key factory to construct keys associated with this project.
KeyFactory keyFactory = datastore.newKeyFactory().kind("FilmData");
Key key = datastore.allocateId(keyFactory.newKey());
Entity dataEntity = Entity.builder(key)
.set("created", filmData.created)
.set("name", StringValue.builder(filmData.name).indexed(true).build())
.set("rating", DoubleValue.builder(UtilsConvert.toDouble(filmData.imdbRating)).indexed(true).build())
.set("ratingCnt", UtilsConvert.toDouble(filmData.imdbRatingCnt))
.set("imdbUrl", StringValue.builder(filmData.imdbUrl).indexed(true).build())
.build();
Then I tried to retrieve the entities by running the following query:
Filter imdbUrlFilter = PropertyFilter.eq("imdbUrl", "http://www.imdb.com/title/tt1431045/");
Query<Entity> query = Query.entityQueryBuilder()
.kind("FilmData")
.filter(imdbUrlFilter)
.orderBy(OrderBy.desc("created"))
.build();
Iterator<Entity> iterator = datastore.run(query);
I expected to retrieve the FilmData with the given "imdbUrl", sorted by "created".
Instead there is an exception:
HTTP ERROR 500
Problem accessing /rest/query/. Reason:
no matching index found.Caused by:
com.google.gcloud.datastore.DatastoreException: no matching index found.
Querying just for one single property works fine, but filtering and sorting - fails.
As described here - I created an index.yaml and put it into my WEB-INF folder, to create a complex 2 property index. This did not help. The exception is still there.
Any ideas why?
indexes:
- kind: FilmData
ancestor: no
properties:
- name: imdbUrl
- name: created
direction: desc
Make sure that your index finished building before trying this code again. You can check index status in developer console (Datastore > Indexes).