开发者

Appengine: DatastoreNeedIndexException when using "order by"

开发者 https://www.devze.com 2023-02-28 02:01 出处:网络
Hello I have this DatastoreNeedIndexException when I try to order by my query. here is the code: @PersistenceCapable

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消