2
votes

I'm trying to get a filtered list from the data store using Objectify, but keep getting an empty list back. I tried adding @index and also creating a datastore-index.xml file, but still get undefined back.

My Listing class:

@Entity
@Index
public class Listing {
    @Id private Long id;
    @Index private double price;

...

My Api:

@Api(name ="xxxx")
@PersistenceCapable(detachable = "true")
public class ListingServiceAPI {

    @ApiMethod(name = "getListings")
    public List<Listing> getListings() {
        return ofy().load().type(Listing.class).filter("price >", 15).list(); //this fails

        //return ofy().load().type(Listing.class).limit(3).list(); //this works
    }
}

datastore-indexes.xml:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<datastore-indexes autoGenerate="true">
  <datastore-index kind="Listing" ancestor="false">
    <property name="price" direction="asc" />
    <property name="category" direction="asc" />
  </datastore-index>
</datastore-indexes>

Anybody know how to fix this to get the filter query to work?

1

1 Answers

2
votes

If you made a property indexed after the data was already stored in the Datastore, your queries will continue to come up empty. This happens because the App Engine indexes all entities as they are saved. You will have to re-save all entities after making changes to the list of indexed properties.