I have a couple of questions about the use of embedded entities in Datastore.
Consider the following simple test case:
Entity entity = new Entity("Person");
entity.setProperty("name", "Alice");
EmbeddedEntity address = new EmbeddedEntity();
address.setProperty("streetAddress", "100 Main Street");
address.setProperty("addressLocality", "Springfield");
address.setProperty("addressRegion", "VA");
entity.setProperty("address", address);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
datastore.put(entity);
Query query = new Query("Person");
FilterPredicate regionFilter =
new FilterPredicate("address.addressRegion", FilterOperator.EQUAL, "VA");
query.setFilter(regionFilter);
List<Entity> results = datastore.prepare(query)
.asList(FetchOptions.Builder.withDefaults());
assertEquals(1, results.size());
This test is failing; the result set is empty.
Here are my questions:
- Am I using FilterPredicate correctly? The documentation does not explain how to reference properties of an EmbeddedEntity. I am guessing that the convention is to use a dot-separated path. But maybe this is not correct.
- Does my test case need to declare indexes for subproperties within the embedded address entity? If so, how?
The Datastore documentation contains the following statement:
"When an embedded entity is included in indexes, you can query on subproperties."
I am following the instructions in the article about Local Unit Testing for Java, but there is nothing in the article that explains how to define indexes in a JUnit test.