Firebase +数据存储= Need_index [英] Firebase + Datastore = need_index

查看:101
本文介绍了Firebase +数据存储= Need_index的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究与Firebase连接的appengine + go教程: https://cloud.google.com/appengine/docs/standard/go/building-app/.可以在 https://github.com上找到该代码. /GoogleCloudPlatform/golang-samples/tree/master/appengine/gophers/gophers-6 ,除了我的Firebase密钥外,其他都是相同的.

我让它在dev_appserver.py下可以在本地正常工作,它查询Vision API并添加标签.但是,在部署到Appengine之后,我在数据存储区上出现索引错误.如果我转到Firebase控制台,则会看到集合(Post)和字段(Posted),这是一个时间戳.

如果我更改此行:,然后一切正常(这很重要请注意,任何Order调用都会导致错误,但我发布的测试记录是随机排列的.

在appengine中运行时的错误消息是:获取帖子:API错误4(datastore_v3:NEED_INDEX):找不到匹配的索引."

我试图创建一个复合索引,或者使用--require_indexes=true在本地进行测试,但这并没有帮助我调试问题.

我已经将其移至可以直接使用Firebase的数据存储库,而不是GCP更新.我从未解决过这个特殊问题,但是能够继续使用我的应用程序:)

解决方案

默认情况下,本地开发服务器会自动创建应用程序中调用的实际查询所需的组合索引.从使用开发服务器创建索引:

开发网络服务器( dev_appserver.py )自动添加 当应用程序尝试执行一个查询时,该文件中的所有项目 需要一个在索引中没有适当条目的索引 配置文件.

在开发服务器中,如果您对应用执行的每个查询都执行 将制作,开发服务器将生成以下内容的完整列表: index.yaml文件中的条目.

当开发Web服务器将生成的索引定义添加到 index.yaml,它在以下行下面执行此操作,如果插入,则将其插入 必要的:

# AUTOGENERATED

开发Web服务器考虑以下的所有索引定义 行是自动的,它可能会更新下面的现有定义 当应用程序进行查询时,此行.

但是您还需要将生成的索引配置部署到数据存储区,并让数据存储区更新索引信息(即,索引进入Serving状态),以使各个查询不会出现NEED_INDEX错误.从更新索引:

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

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

为避免异常,必须为所有索引建立时间. 有关创建索引的更多信息和示例,请参见 部署Go App .

要将索引配置上传到Cloud Datastore,请运行 从index.yaml所在的目录中执行以下命令:

gcloud datastore create-indexes index.yaml

有关信息,请参见 gcloud datastore参考.

您可以使用GCP控制台检查索引的状态.

I'm working through the appengine+go tutorial, which connects in with Firebase: https://cloud.google.com/appengine/docs/standard/go/building-app/. The code is available at https://github.com/GoogleCloudPlatform/golang-samples/tree/master/appengine/gophers/gophers-6, which aside from my Firebase keys is identical.

I have it working locally just fine under dev_appserver.py, and it queries the Vision API and adds labels. However, after I deploy to appengine I get an index error on datastore. If I go to the Firebase console, I see the collection (Post) and the field (Posted) which is a timestamp.

If I change this line: https://github.com/GoogleCloudPlatform/golang-samples/blob/master/appengine/gophers/gophers-6/main.go#L193 to remove the Order("-Posted") then everything works (it's important to note that any Order call causes it to error, except the test records I've posted come in random order.

The error message when running in appengine is: "Getting posts: API error 4 (datastore_v3: NEED_INDEX): no matching index found."

I've attempted to create a composite index, or test locally with --require_indexes=true and it hasn't helped me debug the issue.

Edit: I've moved this over to use Firebase's Datastore libraries directly, instead of the GCP updates. I never solved this particular issue, but was able to move forward with my app actually working :)

解决方案

By default the local development server automatically creates the composite indexes needed for the actual queries invoked in your app. From Creating indexes using the development server:

The development web server (dev_appserver.py) automatically adds items to this file when the application tries to execute a query that needs an index that does not have an appropriate entry in the configuration file.

In the development server, if you exercise every query that your app will make, the development server will generate a complete list of entries in the index.yaml file.

When the development web server adds a generated index definition to index.yaml, it does so below the following line, inserting it if necessary:

# AUTOGENERATED

The development web server considers all index definitions below this line to be automatic, and it might update existing definitions below this line as the application makes queries.

But you also need to deploy the generated index configurations to the Datastore and let the Datastore update indexing information (i.e. the indexes to get into the Serving state) for the respective queries to not hit the NEED_INDEX error. 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. For more information and examples about creating indexes, see Deploying a Go App.

To upload your index configuration to Cloud Datastore, run the following command from the directory where your index.yaml is located:

gcloud datastore create-indexes index.yaml

For information, see the gcloud datastore reference.

You can use the GCP Console, to check the status of your indexes.

这篇关于Firebase +数据存储= Need_index的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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