[英]java - Google Cloud Datastore - Inequality returning “no matching index found”
In Android Studio , I'm trying to use Google Clood Datastore from an Android app. 在Android Studio中 ,我尝试通过Android应用程序使用Google Clood数据存储 。
With the Google example https://cloud.google.com/datastore/docs/concepts/indexes#Datastore_Indexes_and_properties I am able to add Tom (32 years old) and Lucy (30 years old) as Person and as children of the Company Acme. 使用Google示例https://cloud.google.com/datastore/docs/concepts/indexes#Datastore_Indexes_and_properties,我可以将Tom(32岁)和Lucy(30岁)添加为Person和Acme公司的孩子。 I can see these two entries are in the datastore in the Google Developers Console.
我可以看到这两个条目位于Google Developers Console的数据存储区中。
I can retrieve children from Company Acme if I set a query filter as below. 如果我按如下所示设置查询过滤器,则可以从Acme公司检索孩子。
Key acmeKey = makeKey("Company", "Acme").build(); makeFilter("__key__", PropertyFilter.Operator.HAS_ANCESTOR, makeValue(acmeKey)).build()));
makeFilter("age", PropertyFilter.Operator.EQUAL, makeValue(32)).build()
Then, I get the Person Tom. makeFilter("age", PropertyFilter.Operator.EQUAL, makeValue(32)).build()
上方的过滤器中,然后得到Person Tom。 Operator.EQUAL
I put an inequality filter like Operator.LESS_THAN
or Operator.GREATER_THAN
I get the error " no matching index found ". Operator.LESS_THAN
或Operator.GREATER_THAN
这样的不相等过滤器,而不是Operator.EQUAL
,则会收到错误“ 找不到匹配的索引 ”。 I think it's a problem of indexes, but I really don't understand how can I set an index. 我认为这是索引问题,但是我真的不明白如何设置索引。 I use Android Studio and I don't use at all the App Engine.
我使用Android Studio,但完全不使用App Engine。 I just want to retrieve data as I do with MySQL with a simple
WHERE age > 32
. 我只想像在
WHERE age > 32
MySQL中一样检索数据。
Btw, I tried with GQL and I get exactly the exact same problem, work with EQUAL
, but not with GREATER_THAN
(and same in https://developers.google.com/apis-explorer ). 顺便说一句,我尝试使用GQL,但遇到了完全相同的问题,可以使用
EQUAL
,但不能使用GREATER_THAN
(和https://developers.google.com/apis-explorer相同)。
So, does anybody know how I can fix this problem ? 那么,有人知道我该如何解决这个问题? Thanks !!
谢谢 !!
Index configuration for Cloud Datastore is handled using the gcd.sh tool. 使用gcd.sh工具处理Cloud Datastore的索引配置。
It's easiest if you're able to run your queries against the local datastore provided by gcd.sh
. 如果能够对
gcd.sh
提供的本地数据存储区运行查询,这是最简单的。 The tool can determine exactly which indexes you'll need, and then you can use the updateindexes
command to configure them on your production app. 该工具可以准确确定所需的索引,然后可以使用
updateindexes
命令在生产应用程序上对其进行配置。
If not, you can also configure indexes by hand: 如果没有,您也可以手动配置索引:
gcd.sh create <project> -d <project>
<project>/WEB-INF/datastore-indexes.xml
with the following content: <project>/WEB-INF/datastore-indexes.xml
创建一个文件,其内容如下: <?xml version="1.0" encoding="utf-8"?> <datastore-indexes autoGenerate="true"> <datastore-index kind="Company" ancestor="true"> <property name="age" direction="asc" /> </datastore-index> </datastore-indexes>
gcd.sh updateindexes <project>
The exact content of the file will depend on the queries you want to run. 文件的确切内容将取决于您要运行的查询。 This page gives additional details on the format of the indexes file.
此页面提供有关索引文件格式的其他详细信息。
So, as Ed Davisson just said, everything is done with gcd. 因此,正如Ed Davisson所说,一切都由gcd完成。
It took me a lot of time to understand what to do, so I put my experience below, maybe it will be helpful to someone. 我花了很多时间去了解该怎么做,所以我将自己的经验总结如下,也许对某人会有帮助。 I'm working with Ubuntu , I don't know about other OS.
我正在使用Ubuntu ,但对其他操作系统一无所知。
cd Downloads/gcd-v1beta2-rev1-2.1.1
cd Downloads/gcd-v1beta2-rev1-2.1.1
./gcd.sh create -d myDataset myProjectName
where myDataset is the project ID in Google Developers Console (it is composed with 2 random nouns and a number) ./gcd.sh create -d myDataset myProjectName
,其中myDataset是Google Developers Console中的项目ID(由2个随机名词和一个数字组成) As I wanted to retrieve Person who have the ancestor Company and older than 20, I had to add the index as Ed Davisson said 因为我想找回人谁拥有祖先公司与年龄比20,我不得不添加索引爱德戴维森说
<?xml version="1.0" encoding="utf-8"?> <datastore-indexes autoGenerate="true"> <datastore-index kind="Person" ancestor="true"> <property name="age" direction="asc" /> </datastore-index> </datastore-indexes>
In your console, ./gcd.sh updateindexes myProjectName
在您的控制台中,./
./gcd.sh updateindexes myProjectName
Now, in Google Developers Console you can see this new index under Cloud Datastore -> Index 现在,在Google Developers Console中,您可以在Cloud Datastore-> Index下看到此新索引
And finally you can retrieve Person where age > 20 最后,您可以检索年龄> 20岁的人
Key acmeKey = makeKey("Company", "Acme").build();
Query.Builder query = Query.newBuilder();
query.addKindBuilder().setName("Person");
query.setFilter(makeFilter(
makeFilter("__key__",
HAS_ANCESTOR,
makeValue(acmeKey)).build(),
makeFilter("age",
GREATER_THAN,
makeValue(20)).build()));
query.addOrder(makeOrder("age", ASCENDING));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.