title: Google Datastore Index Optimization
body: <p>While designing key-only queries to filter Google Datastore entities, I am generating many composite indexes that are subsets of another index. Is it possible to use the same composite index for queries that filter on a subset of the properties already indexed? For example, if I have the following key-only queries, would it be possible to have less than three indexes?</p>
  
  <pre><code>Query 1: Entities where a = 1, b = 1, c = 1;
  Query 2: Entities where a = 1, b = 1;
  Query 3: Entities where a = 1;
  </code></pre>
  
  <p>Here is a sample of the actual query I am working with:</p>
  
  <pre><code>Query&lt;Key&gt; query = Query.newKeyQueryBuilder()
                .setKind("track")
                .setFilter(CompositeFilter.and(PropertyFilter.eq("status", 1), PropertyFilter.eq("bpm", 138), PropertyFilter.eq("artist", "AVB"), PropertyFilter.eq("label", "Armada")))
                .setOrderBy(OrderBy.asc("date"))
                .build();
  </code></pre>