【问题标题】:Projection query using ancestor throws error 400使用祖先的投影查询抛出错误 400
【发布时间】:2019-10-08 00:46:17
【问题描述】:

通过执行以下操作将以下数据添加到数据存储区:

    key = ds.key(
            'User', 'alice',
            'id'
        )

    entity = datastore.Entity(
        key=key,
    )

    entity.update({"data": "big amount of information"})
    entity.update({"property_name": "confidential"})
    ds.put(entity)

然后,为了减少资源使用,我尝试使用投影查询来仅获取小属性并通过执行以下操作忽略非常大的“数据”:

    key = ds.key(
        'User', 'alice'
    )
    query = ds.query(ancestor=key)
    query.projection = ["property_name"]

    entities = list()

    for entity in query.fetch():
        entities.append(entity)

    return entities

但我收到此错误:

google.api_core.exceptions.InvalidArgument: 400 Unable to plan or invalidate query.

【问题讨论】:

    标签: python google-cloud-datastore gcloud


    【解决方案1】:

    即使您投影的是单个属性,祖先查询也需要复合索引。确保你已经这样做了。

    【讨论】:

    • 你的意思是建立一个 index.yaml 文件?我在文档中看到索引是自动的..这就是为什么我没有研究它..另外,我不在生产中
    • 是的,使用 index.yaml。有内置索引,然后有复合索引。对于未明确指定不索引的属性,内置索引是自动的。但是,内置索引是全局索引,不适合祖先查询。这就是为什么你需要一个复合索引,即使只有一个属性并在索引定义中指定“祖先:是”。
    猜你喜欢
    • 1970-01-01
    • 2013-03-06
    • 1970-01-01
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多