App Engine DataStore - Compound Indexes - datastore-indexes - not working

爷,独闯天下 提交于 2019-12-13 04:47:53

问题


I am unable to search entities using compound indexes. I am using Objectify 4.

Entity configuration:

@Entity
@Unindex
class MyEntity implements Serialiable
{
    @Id String id;
    String one;
    String two;
    long three;
}

Index configuration:

<datastore-indexes autoGenerate="true">
    <datastore-index kind="MyEntity" ancestor="false">
        <property name="one" direction="asc" />
        <property name="two" direction="desc" />
    </datastore-index>
</datastore-indexes>

I see the indexes built in DataStore Indexes. However, when I search using the following query, I always get empty results.

Objectify ofy = ObjectifyService.ofy();
Query<MyEntity> query = ofy.loader()
                           .type(MyEntity.class)
                           .filter("one", "value-one")
                           .filter("two", "value-two");
List<MyEntity> result = query.list();

response.getWriter().println("Size: " + result.size());
//^^ this is always "0" ^^

I'm using HRD.

Any guesses what's going wrong? btw, it used to work until some time back... as early as last week. Now, it doesn't work on dev-server as well as on actual servers.


回答1:


Compound indexes needs all properties involved to be indexed:

@Entity
class MyEntity implements Serialiable
{
    @Id String id;
    @Index String one;
    @Index String two;
    long three;
}

As you are saving the entities without marking the fields as indexed, Objectify is saving those entities without INDEXING them on those fields, thats why your GQL command also return 0 results.



来源:https://stackoverflow.com/questions/20510574/app-engine-datastore-compound-indexes-datastore-indexes-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!