Reputation: 46543
Hello I have this DatastoreNeedIndexException when I try to order by my query.
here is the code:
@PersistenceCapable
public class Gaze {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
Blob image;
@Persistent
Long time;
@Persistent
Long TTL;
@Persistent
String town;
@Persistent
String countryCd;
@Persistent
String tag;
the query:
Query query = pm.newQuery(Gaze.class, "tag == tagParam");
query.declareParameters("String tagParam");
//query.setRange(0,10);
query.setOrdering("time desc");
List<Gaze> results = (List<Gaze>) query.execute(tag);
and the indexes:
<datastore-indexes autoGenerate="false">
<datastore-index kind="Gaze" ancestor="false">
<property name="tag" direction="asc" />
<property name="time" direction="desc"/>
<property name="TTL" direction="desc" />
</datastore-index>
I really don't know where to look. If I remove the order by I have my objects ordered by primarykeys
Upvotes: 2
Views: 687
Reputation: 101149
The index you list includes a TTL
field which your query does not use. Indexes can only be used if they have the exact fields required. You should create an index on tag
and time desc
only.
Upvotes: 0
Reputation: 1229
Are you sure that your indexes are created? You can check it in your Admin Console. Sometimes it takes a while...
Upvotes: 2