如何在Google数据存储中添加组合索引? [英] How to add a composite index in Google Datastore?

查看:113
本文介绍了如何在Google数据存储中添加组合索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在使用Google Datastore来处理我公司的数据库。
今天,我做了一个索引,并成功在'Index'中列出。
但是我做的索引的大小和实体是空的。



google Datastore的文档说索引是自动生成的,但它不是' t。



是否有任何命令或某些事情可以生成索引?

下面的图片是截图。



上面一个是新的。下面这个已经被使用过。



解决方案

事实上,现有的实体不会被自动编入索引。您必须加载并保存所有旧实体(无索引),以便为这些实体创建必要的索引。


请注意,但是,将属性从未索引到索引更改
不会影响可能在
更改之前创建的任何现有实体。对属性的查询过滤不会返回这样的
现有实体,因为实体在创建时未写入查询的
索引。为使实体可以通过
将来的查询访问实体,必须将它们重写到数据存储区,以便它们的
将被输入到适当的索引中。也就是说,您必须针对每个此类现有实体执行
跟踪。



从数据存储中检索(获取)该实体。将实体
写回(放)到数据存储区。同样,将属性从索引更改为
未编制索引仅影响随后写入数据存储库的实体。
具有该属性的任何现有实体的索引条目
将继续存在,直到实体被更新或删除。为避免
不需要的结果,您必须清除所有过滤
的查询的代码或按(现在未指定的)属性进行排序。 (来源


请注意,文档没有明确说明组合索引的相同。在部署新的组合索引时,索引将在开发人员控制台中显示为构建,直至达到正在服务状态。不知道它到底建立了什么,我通常会重新保存所有实体和所有工作。



自动生成是一个这个关键字告诉你是否已经手动创建了这个索引,或者当你做出一个需要这个索引的查询时,它是否由dev服务器创建的。这与任何为实体创建索引的方式和时间都没有关系。


< datastore -indexes> 元素具有autoGenerate属性,
控制是否应该将此文件与
自动生成的索引配置一起考虑。请参阅下面的使用自动索引
配置。 (


创建新索引并且希望为所有现有实体使用此索引时,我建议您创建一个游标查询来处理这个问题。通常我在管理后台公开这个查询,并且运行查询直到没有结果。为什么揭露这件事?如果你有很多实体,这个工作的运行时间可能会比前端允许的60秒或后端的10分钟长。通过公开这一点,我可以使用前端实例时间,而不必担心时间限制。


I'm now using Google Datastore for my company's database. Today, I made a index and it successfully listed in 'Index'. But the size and entities of index which I made is empty.

The documentation of google Datastore says that the index is auto-genarated, but it wasn't.

Is there any command or something to do to generate the index?

The image below is a screenshot.

The upper one is the new one. The below one is already used.

解决方案

As a matter of fact existing entities will not be indexed automatically. You have to load and save all your old entities (without index) in order to have the necessary indexes created for these entities.

Note, however, that changing a property from unindexed to indexed does not affect any existing entities that may have been created before the change. Queries filtering on the property will not return such existing entities, because the entities weren't written to the query's index when they were created. To make the entities accessible by future queries, you must rewrite them to the Datastore so that they will be entered in the appropriate indexes. That is, you must do the following for each such existing entity:

Retrieve (get) the entity from the Datastore. Write (put) the entity back to the Datastore. Similarly, changing a property from indexed to unindexed only affects entities subsequently written to the Datastore. The index entries for any existing entities with that property will continue to exist until the entities are updated or deleted. To avoid unwanted results, you must purge your code of all queries that filter or sort by the (now unindexed) property. (source)

Note that the documentation doesn't explicitly say the same for composed indexes. When you deploy a new composite index the index will appear in the developers console as "building" until it reaches "serving" state. Not sure what exactly it's building there, i usually re-saved all my entities and everything worked as it should.

auto-generated is a keyword that tells you whether you have manually created this index or whether it was created by the dev server when you made a query that required this index. This is in no way linked to how and when the indexes are created for the entities.

The <datastore-indexes> element has an autoGenerate attribute that controls whether this file should be considered along with automatically generated index configuration. See Using Automatic Index Configuration below. (source)

When you created a new index and you want this index for all your existing entities I recommend you create a cursor query to handle this. Usually I expose this query in an admin backend and have the query run until there are no results anymore. Why expose the thing? If you have lots of entities this job may run longer than the allowed 60 seconds in the frontend or 10 minutes in the backend. By exposing this I can use the front end instance time and don't have to worry about the time restrictions.

这篇关于如何在Google数据存储中添加组合索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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