【问题标题】:Appengine query returning no matching index - ObjectifyAppengine 查询返回没有匹配的索引 - 对象化
【发布时间】:2012-06-10 00:06:28
【问题描述】:

我有一些实体,我希望对其进行祖先查询并通过“>”运算符过滤参数。 有问题的实体继承了另一个对象(我认为这不重要)。以下是我的实体类:

@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;
}


}

我的查询代码如下:

Query<PersonnelInfo> q = ofy.query(PersonnelInfo.class).ancestor(tmp).filter("timeUpdated >",     lastSync);

我每次都收到“找不到匹配的索引”错误。没有过滤器,查询工作正常。一些实体缺少“timeUpdated”字段,因为我更改了架构。有些实体是在架构更改后使用 timeUpdated 值创建的,它们不会被返回。我也可以像这样在数据存储查看器上执行 GQL 查询:

select * where FROM PersonnelInfo timeUpdated > 0

我返回了实体,这让我相信索引已创建。我在这里做错了什么?任何帮助将不胜感激!

【问题讨论】:

    标签: google-app-engine gql objectify


    【解决方案1】:

    您需要在 datastore-indexes.xml 中定义一个多属性索引。当你在开发模式下运行查询时,它应该被添加到 datastore-indexes-auto.xml,但结果应该是这样的:

    <datastore-index kind="PersonnelInfo" ancestor="true">
        <property name="timeUpdated" direction="asc"/>
    </datastore-index>
    

    【讨论】:

    • 是的!再次进行救援。谢啦!我的查询从未在开发模式下运行
    • 在必须创建多属性索引时有点困惑。例如,如果您执行查询 ofy().query(someclass).filter("time",time).filter("person",person);对吗?
    • 这个页面有很多讨论:developers.google.com/appengine/docs/java/datastore/queries 结果是当你使用多个属性(或prop+祖先)时需要索引,除了查询引擎有时足够聪明使用单一属性索引进行优化。我相信可以优化二属性相等查询。
    猜你喜欢
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    • 2021-08-15
    • 1970-01-01
    相关资源
    最近更新 更多