"no matching index found" 当使用 "filter" 和 "orderBy" 查询时
"no matching index found" when query using "filter" and "orderBy"
问题
我在为 属性“imdbUrl”查询数据存储并按 属性“创建”排序时遇到 “未找到匹配索引” 异常.
我在 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,按“创建”排序。
反而有一个例外:
HTTP ERROR 500
Problem accessing /rest/query/. Reason:
no matching index found.
Caused by:
com.google.gcloud.datastore.DatastoreException: no matching index found.
仅查询一个 属性 工作正常,但过滤和排序 - 失败。
如所述 here - 我创建了一个 index.yaml 并将其放入我的 WEB-INF 文件夹, 创建一个复杂的 2 属性 索引。这没有帮助。异常仍然存在。
知道为什么吗?
indexes:
- kind: FilmData
ancestor: no
properties:
- name: imdbUrl
- name: created
direction: desc
请确保您的索引已完成构建,然后再尝试此代码。您可以在开发人员控制台(数据存储 > 索引)中检查索引状态。
问题
我在为 属性“imdbUrl”查询数据存储并按 属性“创建”排序时遇到 “未找到匹配索引” 异常.
我在 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,按“创建”排序。
反而有一个例外:
HTTP ERROR 500
Problem accessing /rest/query/. Reason:
no matching index found.Caused by:
com.google.gcloud.datastore.DatastoreException: no matching index found.
仅查询一个 属性 工作正常,但过滤和排序 - 失败。
如所述 here - 我创建了一个 index.yaml 并将其放入我的 WEB-INF 文件夹, 创建一个复杂的 2 属性 索引。这没有帮助。异常仍然存在。
知道为什么吗?
indexes:
- kind: FilmData
ancestor: no
properties:
- name: imdbUrl
- name: created
direction: desc
请确保您的索引已完成构建,然后再尝试此代码。您可以在开发人员控制台(数据存储 > 索引)中检查索引状态。