learner
learner

Reputation: 11780

How to add index to datastore entities after creation

I have an entity kind, say Book. After adding a number of books to my database, I realize that I forgot to @Index one of the fields. So I went ahead and index the field. How do I get the index to apply to the pre-existing entities/instances? Also, since it's a single index do I have to declare it in datastore-indexes.xml?

Upvotes: 1

Views: 48

Answers (1)

stickfigure
stickfigure

Reputation: 13556

You load() and save() every individual entity.

Multi-property indexes in datastore-indexes.xml are built/deleted/updated automatically by GAE. Single-property indexes are defined by you on a per-entity basis.

There are benefits and disadvantages of this - the main benefit being that you have the option of indexing some entities and not others based on arbitrary logic (it becomes a kind a partial index). The main disadvantage is that when you make changes, you have to rewrite the entities yourself.

Upvotes: 1

Related Questions