【问题标题】:How to fetch the indexes/Columns data from Google Cloud Platform using GQL(Google Query Language)如何使用 GQL(谷歌查询语言)从谷歌云平台获取索引/列数据
【发布时间】:2018-09-05 08:05:04
【问题描述】:

种类名称:invoice_header

Name/ID                       :id=4829628648652800
amount                        :2900
booking_ids                   :1,2
created_at                    :2018-09-04 10:20:30
discount_amount               :23
due_amount                    :9999
indicator                     :PO
invoice_date                  :2018-09-04
invoice_id                    :451
issued_to                     :P
location_id                   :12
net_payable_amount            :999
order_or_po_id                :533
paid_amount                   :555
partner_id                    :400
payment_mode_promotion_amount :0
status                        :NP
tax_amount                    :34
updated_at                    : 

我尝试使用以下 GQL 查询从上述类型中获取数据,但出现以下错误。

GQL 查询错误:您的数据存储区没有复合索引 此查询需要(开发人员提供)。

select invoice_date from invoice_header where location_id ='12' and invoice_date >= '2018-09-01' and invoice_date <= '2018-09-05'

【问题讨论】:

    标签: google-cloud-platform google-cloud-datastore


    【解决方案1】:

    您是否在应用程序中添加了索引文件?

    正如文档[1] 中所述,应用程序进行的每个 Cloud Datastore 查询都需要相应的索引。自动创建简单查询的索引,例如对单个属性的查询。复杂查询的索引必须在名为 index.yaml 的配置文件中定义。此文件与应用程序一起上传,以在 Cloud Datastore 中创建索引。

    复合索引支持复杂查询,并在索引配置文件 (index.yaml) 中定义。

    在您的情况下,您需要添加一个包含 location_id 和 invoice_date 属性的复合索引。这是 index.yaml 的一个示例:

    索引: - 种类:invoice_header 特性: - 名称:location_id 方向:上升 - 名称:发票日期 方向:升序

    修改完索引配置文件后,运行“gcloud datastore create-indexes”命令将索引投入使用。

    [2] 中,您将找到有关索引的更广泛解释。

    干杯。

    【讨论】:

    • 感谢您的回复,我的项目已经包含 index.properties 文件。该文件包含所有种类及其对应的索引。是否足够,或者我必须将文件重命名为 index.yaml。
    • 是的,需要将文件名改为“index.yaml”,然后执行命令“gcloud datastore create-indexes”。
    • Magdiel Garcia 先生,它正在工作......非常感谢您的支持。
    猜你喜欢
    • 2013-11-24
    • 2018-11-08
    • 1970-01-01
    • 2020-06-02
    • 2018-01-10
    • 2017-09-27
    • 2020-12-11
    • 1970-01-01
    • 2020-07-26
    相关资源
    最近更新 更多