Objectify does not return data when querying with multiple filter(), even though the respective attributes are set as multi index

StackOverflow https://stackoverflow.com/questions/23181441

  •  06-07-2023
  •  | 
  •  

سؤال

I have an existing datastore entity as below:

@Data
@Entity
public class Data
{
    @Id @Index long id;
    long subId;
    boolean expired;
    boolean claimed;
}

I am in need to filter the data based on subId, expired an claimed fields, so I created a multi index using datastore-indexes.xml as below:

<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes autoGenerate="true">
<datastore-index kind=“Data” ancestor="false">
    <property name=“subId” direction="asc" />
    <property name="expired" direction="asc" />
    <property name="claimed" direction="asc" />
</datastore-index>
</datastore-indexes>

This entity is completely a new entity and below are two new records added into the entity kind:

Column : Data

id : 1
subId : 1
expired : false
claimed : false

id : 2
subId : 1
expired : false
claimed : false

However when I try query the Data entity using the below logic, I do get empty data out:

List<Data> data = ofy.load().type( Data.class )
    .filter( "subId = ", 1 )
    .filter( "expired = ", Boolean.FALSE )
    .filter( "claimed = ", Boolean.FALSE )
    .list();

PS - I see that index status is currently Serving and I except the data to be retrieved properly. Please help me if am missing anything?

هل كانت مفيدة؟

المحلول

In order for an entity to show up in a multiple-property index, each of the individual fields in that entity must be indexed. Put @Index on the three fields and resave the entity.

Putting @Index on the id field has no effect, btw. Id/parent fields aren't real properties, they are just part of the key - which is always indexed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top