Google App Engine 错误:找不到匹配的索引。 (爪哇)

发布于 2024-10-26 02:42:51 字数 777 浏览 0 评论 0原文

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

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 am writing a query but it always says "No matching index found". I don't know why. My code is as below:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

×眷恋的温暖 2024-11-02 02:42:51

我认为您需要配置数据存储区索引。 Eclipse 中可能已在 WEB-INF/appengine- generated/datastore-indexes-auto.xml 中为您生成了一个文件,您只需将其复制到 WEB-INF/datastore-indexes 即可。 xml 并再次部署。

I believe you need to configure a Datastore Index. There's probably one already generated for you in Eclipse at WEB-INF/appengine-generated/datastore-indexes-auto.xml that you just need to copy to WEB-INF/datastore-indexes.xml and deploy again.

巴黎盛开的樱花 2024-11-02 02:42:51

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

当我发现这个时我踢了自己
错误是您没有与查询想要执行的索引相匹配的索引。每个实体可以有多个索引。

在 Logcat 中,错误会准确地告诉您要设置什么索引以及元素需要采用什么顺序。

即,如果错误表明它想要(它不会被很好地格式化):

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

那么 Project ->战争-> WEB-INF->应用程序引擎生成 -> datastore-indexes-auto.xml 并准确添加该内容。然后,重新部署该项目。

接下来进入您的 Google Cloud Console 并查看数据存储 ->索引。应该说索引正在准备中(如果您可以终止所有连接的应用程序并关闭控制台中的实例,则速度会更快)。

一旦它移入其他索引列表,重新运行您的应用程序,它就不会再出现与索引有关的错误。

先生们/女士们,去拿吧

Because this needs to be somewhere on the internet...

I kicked myself when I found this out
The error is you do not have a index matching what the query would like to perform. You can have multiple indexes for each entity.

In the Logcat, error, it will tell you exactly what index to set and what order the elements need to be.

ie, if the error says it wants (it wont be nicely formatted):

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

then Project -> war -> WEB-INF -> appengine-generated -> datastore-indexes-auto.xml and add exactly that. Then, redeploy the project.

Next go into your Google Cloud Console and look at Datastore -> indexes. It should say that the index is being prepared (This goes quicker if you can kill all apps connected and shut down the instance in the console).

Once this has moved into the list of other indexes, rerun the your application and it wont error out with regards to the index anymore.

Go get it Gentlemen/Ladies

韬韬不绝 2024-11-02 02:42:51

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

尝试从索引定义中删除类别行,或交换categoryupload_date 的顺序,以生成upload_date索引的主要排序顺序。如果代码的另一部分依赖于类别行,则可能必须创建两个单独的索引(这会产生一些计算成本)。

编辑:请参阅下面尼克·约翰逊的评论。额外的参数。

The index you define must hold all possible results in the order they will be returned. Your query asks for a particular emp_Id, ordered by upload_date, but your index is ordered primarily by category.

Try removing the category line from your index definition, or swapping the order of category and upload_date, to make upload_date the primary sort order for the index. If another part of your code relies on the category line, you may have to make two separate indices (which incurs some computational cost).

Edit: see comment below by Nick Johnson re. extra parameters.

落花浅忆 2024-11-02 02:42:51

我目前在执行单个属性查询时遇到了这个问题,例如:

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

在我的情况下,我不应该收到任何错误,但是我收到错误 9:未找到匹配的索引。

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

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

但这肯定是一个错误..!

I am running into this issue at the moment when doing a single property query such as:

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

In my case, I should not be getting any errors, however I get Error 9: No matching index found.

If I defined the single property index twice in the yaml, it works:

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

but this for sure must be a bug..!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文