Appengine: DatastoreNeedIndexException when using "order by"
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.declareParameter开发者_JAVA百科s("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
Are you sure that your indexes are created? You can check it in your Admin Console. Sometimes it takes a while...
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.
精彩评论