App Engine DataStore - Compound Indexes - datastor

2019-08-26 01:12发布

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条回答
做个烂人
2楼-- · 2019-08-26 01:45

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.

查看更多
登录 后发表回答