简体   繁体   中英

DatastoreNeedIndexException: no matching index found. Using Objectify

Having this error after deploying my code to cloud, using google appengine, i use objectify indexing for my filtering.

here is my java class (Entity) file containing the index

@Entity
public class Session{
   @Index private Integer year;
   @Index private Key<Institute> institute;
  //some other manipulation goes below
   }

When am trying to call a list of entity from datastore using objectify like this

ofy().load().type(Session.class).filter("institute",t).order("year").list();//order by year

it throws the below error on my console , the below image shows it , sorry not too clear

在此处输入图片说明

You need to add suggested index definition to your datastore-indexes.xml file. If you don't have this file, you need to create it in /war/WEB-INF/ folder:

<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes
  autoGenerate="true">

    <datastore-index kind="Session" ancestor="false" source="manual">
        <property name="institute" direction="asc"/>
        <property name="year" direction="asc"/>
    </datastore-index>
</datastore-indexes>

Note that most index definitions can be auto-genereated when you test your app on the development server, but sometimes it's not easy to test every possible use case and manual definitions may be an easier option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM