谷歌应用引擎错误。没有找到匹配的索引。(Java)

问题描述 投票:1回答:4

我正在写一个查询,但它总是说 "没有找到匹配的索引"。我不知道为什么。我的代码如下。

Query query = pm.newQuery(Classified.class);
query.setFilter("emp_Id == emp");
query.setOrdering("upload_date desc");
query.declareParameters("String emp");
List<Classified> results = (List<Classified>)query.execute(session.getAttribute("emp_Id").toString()); 

<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes autoGenerate="true">
  <datastore-index kind="Classified" ancestor="false">
    <property name="emp_Id" direction="asc" />
    <property name="category" direction="asc" />
    <property name="upload_date" direction="desc" />
  </datastore-index>
</datastore-indexes> 

我加了上面的索引,但没有用。 I have added the above index, but it did not help.

java google-app-engine jdo
4个回答
6
投票

我相信你需要配置一个 数据存储索引. 也许在Eclipse中已经为你生成了一个在 WEB-INF/appengine-generated/datastore-indexes-auto.xml 您只需要复制到 WEB-INF/datastore-indexes.xml 并再次部署。


3
投票

因为这需要在互联网上的某个地方... ...

当我发现这个问题的时候,我踢了自己一脚错误的是你没有一个与查询想要执行的内容相匹配的索引,你可以为每个实体设置多个索引。你可以为每个实体有多个索引。

在Logcat中,错误,它会告诉你到底要设置什么索引,元素需要什么顺序。

即,如果错误说它要(它不会有很好的格式)。

<datastore-index kind="Classified" ancestor="false">
    <property name="category" direction="desc" />
    <property name="upload_date" direction="desc" />
  </datastore-index>

那么 Project -> war -> WEB-INF -> appengine-generated -> datastore-indexes-auto.xml 并准确地添加这些内容。然后,重新部署项目。

接下来进入你的Google Cloud Console,查看Datastore -> indexes。它应该说正在准备索引(如果你能在控制台中杀死所有连接的应用程序并关闭实例,这将更快)。

一旦这个索引移到了其他索引列表中,重新运行你的应用程序,它就不会再在索引方面出错了。

去得到它,先生们女士们


1
投票

你所定义的索引必须按照返回的顺序保存所有可能的结果。 你的查询要求一个特定的emp_Id,按upload_date排序,但你的索引主要是按类别排序。

请尝试从您的索引定义中删除类别行。或调换顺序 categoryupload_date, 以使 upload_date 索引的主要排序顺序。 如果你的代码的另一部分依赖于类别行,你可能需要制作两个单独的索引(这需要一些计算成本)。

编辑:参见下面Nick Johnson关于额外参数的评论。


0
投票

我目前在做单一属性查询时遇到了这个问题,比如。

 const query = datastore
  .createQuery('Emailing_dev')
  .filter('status', '=', 'Scheduled')

在我的例子中,我不应该得到任何错误,但是我得到错误9: 没有找到匹配的索引。

如果我在yaml中定义了两次单一属性索引,它就会工作。

indexes:
  - kind: Emailing_dev
    properties:
    - name: status
    - name: status

但这肯定是个bug... !!!

© www.soinside.com 2019 - 2024. All rights reserved.