使用某些索引属性查询数据存储 [英] Querying Datastore using some of the indexed properties

查看:50
本文介绍了使用某些索引属性查询数据存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试Cloud Datastore的索引,但无法弄清解决查询所需的配置.

I am trying out Cloud Datastore's indexes, and I cannot figure out the configuration I need to resolve my queries.

我创建了几个相同类型的实体(命名为对象"),它们全部具有5个同等命名的属性(property_0,property_1,...,property_4).然后,我为此创建了一个复合索引,为所有5个属性建立索引,并在最后一个位置设置property_4,因为我想对其应用不等式过滤器.

I have created a few entities of the same kind (named "object"), all of them with 5 properties named equally (property_0, property_1, ..., property_4). Then, I have created a composite index for that kind, indexing all 5 properties, and setting property_4 in the last place because I want to apply inequality filters on it.

索引的定义是:

indexes:
- kind: object
  ancestor: no
  properties:
  - name: property_0
    direction: asc
  - name: property_1
    direction: asc
  - name: property_2
    direction: asc
  - name: property_3
    direction: asc
  - name: property_4
    direction: asc

我要解决的查询将始终在property_4上应用不等式过滤器,并且在某些其他属性上可能会有过滤器.一些例子:

The queries I am trying to resolve will always apply an inequality filter on property_4, and there may be filters on some of the other properties. Some examples:

  • SELECT * FROM对象在哪里property_4> 5 AND property_0 = true
  • SELECT * FROM对象在哪里property_4> 5 AND property_4< 10与 property_1 ='已批准'
  • SELECT * FROM对象在哪里property_4> 8 AND property_2 = 100 AND property_3 = true
  • SELECT * FROM对象在哪里property_4> 15 AND property_0 = true AND property_1 ='草稿'AND property_2 = 10 AND property_3 = false
  • SELECT * FROM object WHERE property_4 > 5 AND property_0 = true
  • SELECT * FROM object WHERE property_4 > 5 AND property_4 < 10 AND property_1 = 'approved'
  • SELECT * FROM object WHERE property_4 > 8 AND property_2 = 100 AND property_3 = true
  • SELECT * FROM object WHERE property_4 > 15 AND property_0 = true AND property_1 = 'draft' AND property_2 = 10 AND property_3 = false

唯一有效的查询是,如果我对索引中的每个属性进行过滤,其余查询将显示错误消息您的数据存储区没有(开发人员提供的)综合索引此查询."

The only query that works is if I filter on every property in the index, the rest of them show the error message "Your Datastore does not have the composite index (developer-supplied) required for this query."

不是所有查询都可以通过创建的索引来解决吗?还是我需要为要应用的过滤器的每个组合创建索引? (即,一个索引用于过滤property_4和property_0;另一个索引用于property_4和property_1;另一个索引用于property_4,property_2和property_3; ...)

Shouldn't all the queries be resolved by the created index? Or do I need to create an index for every combination of the filters I want to apply? (i.e. one index for filtering property_4 and property_0; another one for property_4 and property_1; another one for property_4, property_2 and property_3; ...)

推荐答案

您是正确的,您需要为要应用的过滤器的每个组合创建索引.

You are correct, you will need to create indexes for every combination of the filter you want to apply.

您可以通过以下方式在 index.yaml 文件中为单独的查询指定索引:

You can specify the indexes for separate queries in the index.yaml file the following way:

indexes:
- kind: object
  properties:
  - name: property_0
  - name: property_1
  - name: property_2
  - name: property_3
  - name: property_4

- kind: object
  properties:
  - name: property_3
  - name: property_4
  - name: property_0

...

这篇关于使用某些索引属性查询数据存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆