I would like to know if it is possible to design Google Datastore indexes and queries in a way that I can reduce the number of composite indexes needed for my project.
I have been trying to use one index that works with both of my queries like the example found here. However, I cannot find a way for one index to work with my query needs, nor do I know if one even exists. Below are the two queries I have been working with and the Datastore index suggestions I receive for both. Is there something I could do differently to make these queries work with a single index?
Query 1:
CompositeFilter.and(
CompositeFilter.and(PropertyFilter.gt("time", time1), PropertyFilter.lt("time", time2)),
PropertyFilter.eq("user", user1),
PropertyFilter.eq("color", color1),
PropertyFilter.eq("bpm", bpm1));
addOrderBy(OrderBy.asc("time"), OrderBy.asc("location"));
Query 1 Index Suggestion:
- name: color
- name: bpm
- name: user
- name: time
- name: location
Query 2:
CompositeFilter.and(
CompositeFilter.and(PropertyFilter.gt("time", time1), PropertyFilter.lt("time", time2)),
PropertyFilter.eq("user", user1));
addOrderBy(OrderBy.asc("time"), OrderBy.asc("color"), OrderBy.asc("bpm"), OrderBy.asc("location"));
Query 2 Index Suggestion:
- name: user
- name: time
- name: color
- name: bpm
- name: location