如何配置 Google 不平等过滤器的数据存储索引和公平过滤器

How to config Google Datastore index for inequality filter with equity filter

我正在研究如何为 Google 数据存储构建索引以执行以下查询:

SELECT * FROM Place WHERE type = 'something' AND geohashes >= 'XXX' AND geohashes <= 'YYY'

我创建了以下索引。但是,当我执行该查询时,我收到一条错误消息:“找不到匹配的索引”

<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes
  autoGenerate="true">
    <datastore-index kind="Place" ancestor="false">
        <property name="geohashes" direction="asc" />
        <property name="geohashes" direction="desc" />
        <property name="type" direction="asc" />
    </datastore-index>
   <datastore-index kind="Place" ancestor="false">
        <property name="geohashes" direction="asc" />
        <property name="type" direction="asc"/>
    </datastore-index>
   <datastore-index kind="Place" ancestor="false">
        <property name="geohashes" direction="desc" />
        <property name="type" direction="asc" />
    </datastore-index>
</datastore-indexes>

如何在 Datastore 中建立索引以便我可以进行上述查询?谢谢!

当 运行ning 使用 Datastore 查询时,您必须提供非常具体的索引。这很重要,因为它允许 Datastore 保证所有查询随结果集的大小缩放,而不是你的数据集。

一般来说,我建议首先 运行使用本地开发服务器来编译您的代码。这将为您的查询生成适当的索引。您可以 run the server 使用命令:

appengine-java-sdk/bin/dev_appserver.sh <war-location>

当您 运行 数据存储区查询时,文件 datastore-indexes-auto.xml 将在您的应用程序目录中生成。这将包含您执行的任何查询的必要索引。

对于您的特定查询,您的索引属性顺序不正确。

来自index documentation

The rows of an index table are sorted first by ancestor and then by property values, in the order specified in the index definition.

对于您的特定查询,您需要索引:

<datastore-index kind="Place" ancestor="false">
  <property name="type" direction="asc"/>
  <property name="geohashes" direction="asc" />  
</datastore-index>