【问题标题】:"no matching index found" when query using "filter" and "orderBy"使用“filter”和“orderBy”查询时“找不到匹配的索引”
【发布时间】:2016-03-03 19:16:41
【问题描述】:

问题

在向数据存储区查询属性“imdbUrl”并按属性“created”排序时遇到“找不到匹配的索引”异常。

我在 GAE-Datastore 中定义了以下实体:

    // Create a Key factory to construct keys associated with this project.
    KeyFactory keyFactory = datastore.newKeyFactory().kind("FilmData");
    
    Key key = datastore.allocateId(keyFactory.newKey());
    Entity dataEntity = Entity.builder(key)
            .set("created", filmData.created)
            .set("name", StringValue.builder(filmData.name).indexed(true).build())
            .set("rating", DoubleValue.builder(UtilsConvert.toDouble(filmData.imdbRating)).indexed(true).build())
            .set("ratingCnt", UtilsConvert.toDouble(filmData.imdbRatingCnt))
            .set("imdbUrl", StringValue.builder(filmData.imdbUrl).indexed(true).build())
            .build();

然后我尝试通过运行以下查询来检索实体:

    Filter imdbUrlFilter =  PropertyFilter.eq("imdbUrl", "http://www.imdb.com/title/tt1431045/");
    
    Query<Entity> query = Query.entityQueryBuilder()
            .kind("FilmData")
            .filter(imdbUrlFilter)
            .orderBy(OrderBy.desc("created"))
            .build();

    Iterator<Entity> iterator = datastore.run(query);

我希望使用给定的“imdbUrl”检索 FilmData,按“created”排序。

反而有一个例外:

HTTP 错误 500

访问 /rest/query/ 时出现问题。原因:
没有找到匹配的索引。

原因:
com.google.gcloud.datastore.DatastoreException:找不到匹配的索引。

仅查询一个属性可以正常工作,但过滤和排序 - 失败。

here 所述 - 我创建了一个 index.yaml 并将其放入我的 WEB-INF 文件夹中,以创建一个复杂的 2 属性索引。这没有帮助。异常仍然存在。

有什么想法吗?

indexes:

- kind: FilmData
  ancestor: no
  properties:
  - name: imdbUrl
  - name: created
    direction: desc

【问题讨论】:

    标签: google-app-engine google-cloud-datastore


    【解决方案1】:

    在再次尝试此代码之前,请确保您的索引已完成构建。您可以在开发者控制台中查看索引状态(Datastore > Indexes)。

    【讨论】:

    • 我应该已经部署了应用程序,以便数据存储服务器了解索引。
    • 需要注意gcloud app deploy index.yamlglcoud app deploy 本身不包括 index.yaml,在尝试最初设置我的索引并在文档中的某处发现此注释时感到非常沮丧(对于 cron.yaml 和 dispatch.yaml 显然也是如此)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    • 2018-10-06
    • 2019-01-14
    • 2021-01-05
    • 2017-03-22
    • 1970-01-01
    相关资源
    最近更新 更多