Add index to entity property that is already live in the datastore on Google App Engine

旧巷老猫 提交于 2020-01-11 10:13:26

问题


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).


回答1:


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.



来源:https://stackoverflow.com/questions/34582702/add-index-to-entity-property-that-is-already-live-in-the-datastore-on-google-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!