doushadu0901 2018-07-20 13:44
浏览 32
已采纳

Google App Engine for Golang中将index.yaml导入到哪里?

Playing with Bookshelf tutorial and the Auth package.

The ListBooksCreatedBy query is failing with this error:

could not list books: datastoredb: could not list books: rpc error: code = FailedPrecondition desc = no matching index found. recommended index is:   
- kind: Book   
  properties:   
  - name: CreatedByID   
  - name: Title  

However, index.yaml does exist and is in the same directory as app.yaml :
index YAML content:

indexes:   

# This index enables filtering by "CreatedByID" and sort by "Title".   
- kind: Book   
  properties:   
  - name: CreatedByID   
    direction: asc   
  - name: Title   
    direction: asc   

Why would the index not be imported?

Where in the Golang App Engine code is the index.yaml imported?

I searched the src and found nothing.

  • 写回答

1条回答 默认 最新

  • dongpouda6700 2018-07-20 14:33
    关注

    The index.yaml file is not intended to be imported/used in your application code, it is intended to be deployed to the Datastore service (separately/independently from your app deployments!) to configure its indexing activities. From Updating indexes:

    You upload your index.yaml configuration file to Cloud Datastore with the gcloud command. If the index.yaml file defines any indexes that don't exist in Cloud Datastore, those new indexes are built.

    It can take a while for Cloud Datastore to create all the indexes and therefore, those indexes won't be immediately available to App Engine. If your app is already configured to receive traffic, then exceptions can occur for queries that require an index that is still in the process of being built.

    To avoid exceptions, you must allow time for all the indexes to build.

    Only after proper deployment and, if needed, the completion of the index update operation (i.e. the index reaches the Serving state) the app's queries needing that index can work.

    The index.yaml file is also used by the local development server in its datastore emulation. By default it automatically updates the file with the necessary indexes for the queries it encounters, but the file isn't automatically deployed to the Datastore. But you can disable this behaviour using the --require_indexes option. From Local Development Server Options:

    --require_indexes=yes|no

    Disables automatic generation of entries in the index.yaml file. Instead, when the application makes a query that requires that its index be defined in the file and the index definition is not found, an exception will be raised, similar to what would happen when running on App Engine. The default value is no.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 docker环境配置
  • ¥20 绿盟安全扫描--检测到目标站点存在javascript框架库漏洞
  • ¥30 Android STD快速启动
  • ¥15 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现