将索引添加到Google App Engine上已存在于数据存储中的实体属性 [英] Add index to entity property that is already live in the datastore on Google App Engine

查看:102
本文介绍了将索引添加到Google App Engine上已存在于数据存储中的实体属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你应该在你的实体模型的所有属性中添加@Index来添加一个索引,但是如果你忘记了,并且你的实体已经存在于数据存储中,那该怎么办?



有没有办法通过开发人员控制台或其他方式手动向所有这些属性添加索引?



我发现如果添加@Index指向您的实体并重新部署该项目,该实体的所有新写入都会将该属性编入索引。但是,该属性的所有现有写入操作都不会被编入索引(因此不可搜索)。 解决方案

写入数据存储区。为了确保现有实体的索引得到更新,一种方法是读取每个实体并将其写回到成本高昂的位置,但可以批量执行(例如在计划任务中)。



你没有提到你正在使用哪种语言 - 我知道它不是Python,因为那里没有 @index 。在Python中,当我使用新的索引更新index.yaml并上传它时,App Engine负责为我进行重新索引(可能需要一段时间,但它确实发生在它自己的)。无论您最喜欢的语言是什么,您都可以利用Python运行时的这一特性,因为App Engine允许应用程序(共享相同数据存储)的各个模块使用不同的语言 - 只需在Python中添加一个模块,在Python的 ndb 中复制模型,并像使用全Python应用程序一样使用index.yaml。这应该工作得很好,唯一的困难是在数据存储顶部使用任何图层(对象化或任何其他)以Python方式对模型进行逆向工程,从而深入。


I know you are supposed to add @Index to all properties in your entity model to add an index, but what if you forget and there are already live writes of your entity in the datastore?

Is there a way to manually add an index to all those properties via the developers console or some other way?

I found that if you add @Index to your entity and re-deploy the project, all new writes of that entity will have that property indexed. However, all existing writes of that property will not be indexed (and therefore, unsearchable).

解决方案

Indices are updated when an entity is written to the datastore. To ensure indices are updated for existing entities, one approach is to read every entity and write it right back -- costly, to be sure, but doing it in batches (e.g in scheduled tasks) would work.

You don't mention which language you're using -- I know it's not Python because there's no @index there. In Python, when I update index.yaml with new indices and upload it, App Engine takes care of doing the re-indexing for me (it can take quite a while, but, it does "happen on its own").

Whatever your favorite language, you could take advantage of that feature of the Python runtime since App Engine allows various modules of an app (which share the same datastore) to be in different languages -- just add a module in Python, reproducing your models in Python's ndb, and use index.yaml just as you would if you were doing an all-Python application... that should work just fine, the only difficulty being to "dig inside" whatever layers you're using on top of the datastore (objectify, or whatever) to reverse engineer your models in Python terms.

这篇关于将索引添加到Google App Engine上已存在于数据存储中的实体属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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