Appengine query returning no matching index - Objectify
-
12-06-2021 - |
Question
I have some entities that I wish to do an ancestor query on and filter a parameter by the ">" operator. The entity in question inherits another object(I don't think this should matter). Below are my entity classes:
@Indexed
public class ValidatedObject {
public Long timeCreated=System.currentTimeMillis();
public Long timeUpdated=System.currentTimeMillis();
public Long getTimeUpdated() {
return timeUpdated;
}
public void setTimeUpdated(Long timeUpdated) {
this.timeUpdated = timeUpdated;
}
public Boolean validated=false;
@Unindexed
public String validatedID;
@Unindexed
private Long validatedTime;
@Unindexed
private String creatorID;
public Long getTimeCreated() {
return timeCreated;
}
public void setTimeCreated(Long timeCreated) {
this.timeCreated = timeCreated;
}
public boolean isValidated() {
return validated;
}
public void setValidated(boolean validated) {
this.validated = validated;
}
public String getValidatedID() {
return validatedID;
}
public void setValidatedID(String validatedID) {
this.validatedID = validatedID;
}
public Long getValidatedTime() {
return validatedTime;
}
public void setValidatedTime(Long validatedTime) {
this.validatedTime = validatedTime;
}
public String getCreatorID() {
return creatorID;
}
public void setCreatorID(String creatorID) {
this.creatorID = creatorID;
}
}
@Cached
@Entity
public class PersonnelInfo extends ValidatedObject{
@Id
public String keyName;
@Parent Key<Department> department;
private Long fdID;
@Unindexed
private String userKeyName;
private String firstName;
private String lastName;
@Unindexed
private String address,city,county,state;
@Unindexed
private String cellPhone,homePhone,otherPhone;
public PersonnelInfo(){
}
public PersonnelInfo(String email){
keyName=email;
}
@Override
public Long getTimeUpdated() {
return timeUpdated;
}
@Override
public void setTimeUpdated(Long time) {
timeUpdated=time;
}
}
My query code is as follows:
Query<PersonnelInfo> q = ofy.query(PersonnelInfo.class).ancestor(tmp).filter("timeUpdated >", lastSync);
I am getting the "no matching index found" error everytime. The query works fine without the filter. Some of the entities are missing the "timeUpdated" field because I changed the schema. There are some entities that have been created after the schema change with timeUpdated values and they are not returned. Also I can do a GQL query on the datastore viewer like this:
select * where FROM PersonnelInfo timeUpdated > 0
and I am returned entities, which makes me believe the index is created. What am I doing wrong here? Any help would be appreciated!
Solution
You need a multi-property index defined in your datastore-indexes.xml. It should be added to datastore-indexes-auto.xml when you run the query in dev mode, but the result should look like this:
<datastore-index kind="PersonnelInfo" ancestor="true">
<property name="timeUpdated" direction="asc"/>
</datastore-index>