gpt4 book ai didi

Firebase + 数据存储 = need_index

转载 作者:太空宇宙 更新时间:2023-11-03 15:37:37 25 4
gpt4 key购买 nike

我正在学习与 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 key 之外,它是相同的。

我让它在 dev_appserver.py 下在本地正常工作,它查询 Vision API 并添加标签。但是,在我部署到 appengine 之后,我在数据存储上遇到了索引错误。如果我转到 Firebase 控制台,我会看到集合 (Post) 和作为时间戳的字段 (Posted)。

如果我更改此行:https://github.com/GoogleCloudPlatform/golang-samples/blob/master/appengine/gophers/gophers-6/main.go#L193删除 Order("-Posted") 然后一切正常(重要的是要注意任何 Order 调用都会导致它出错,除了我发布的测试记录来顺序随机。

在 appengine 中运行时的错误信息是:“Getting posts: API error 4 (datastore_v3: NEED_INDEX): no matching index found.”

我尝试创建复合索引,或使用 --require_indexes=true 在本地进行测试,但它没有帮助我调试问题。

编辑:我已将其移至直接使用 Firebase 的数据存储库,而不是 GCP 更新。我从未解决过这个特定问题,但能够继续使用我的应用程序实际运行 :)

最佳答案

默认情况下,本地开发服务器会自动创建在您的应用程序中调用的实际查询所需的复合索引。来自 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.

但您还需要将生成的索引配置部署到 Datastore 并让 Datastore 更新索引信息(即索引进入 Serving 状态)以防止相应查询命中 NEED_INDEX 错误。来自 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,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50482669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com