Google App Engine for Golang中将index.yaml导入到哪里? [英] Where is index.yaml imported in Google App Engine for Golang?

查看:57
本文介绍了Google App Engine for Golang中将index.yaml导入到哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用书架教程和Auth软件包.

Playing with Bookshelf tutorial and the Auth package.

ListBooksCreatedBy查询失败,并显示以下错误:

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  

但是,index.yaml确实存在,并且与app.yaml位于同一目录中:
索引YAML内容:

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   

为什么不导入索引?

index.yaml在Golang App Engine代码中的何处导入?

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

我搜索了src,却一无所获.

I searched the src and found nothing.

推荐答案

index.yaml 文件无意在您的应用程序代码中导入/使用,而是打算部署到数据存储区服务(与您的应用程序部署分开/独立!)来配置其索引活动.从更新索引:

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:

您将 index.yaml 配置文件上传到Cloud Datastore使用gcloud命令.如果 index.yaml 文件定义了任何索引Cloud Datastore中不存在的索引,则会构建这些新索引.

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.

Cloud Datastore可能需要一段时间才能创建所有索引,并且因此,这些索引将不会立即提供给App Engine.如果您的应用程序已配置为接收流量,则出现异常对于需要仍在索引中的索引的查询,可能会发生建立过程.

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.

只有在正确部署后,并且在需要时完成索引更新操作(即索引达到 Serving 状态),需要该索引的应用程序查询才能正常工作.

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.

index.yaml 文件也由本地开发服务器在其数据存储区仿真中使用.默认情况下,它会为遇到的查询自动使用必要的索引更新文件,但是该文件不会自动部署到数据存储区.但是您可以使用-require_indexes 选项禁用此行为.来自本地开发服务器选项:

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

index.yaml 文件中禁用自动生成条目.相反,当应用程序进行查询时要求在文件中定义索引,但找不到索引定义,将引发异常,类似于在App Engine.默认值为 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.

这篇关于Google App Engine for Golang中将index.yaml导入到哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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