Retroactive indexing in Google Cloud Datastore

前端 未结 2 2050
借酒劲吻你
借酒劲吻你 2020-12-06 12:20

There are many properties in my model that I currently don\'t need indexed but can imagine I might want indexed at some unknown point in the future. If I explicitly set

2条回答
  •  北海茫月
    2020-12-06 12:38

    To index properties of existing entities (as per the documentation):

    1. Retrieve (get) the entity from the Datastore.
    2. Write (put) the entity back to the Datastore.

    didn't work for me. I employed appengine-mapreduce library and wrote a MapOnlyMapper using DatastoreMutationPool for indexing all the existing entities in Datastore.

    Lets assume the property name was unindexed and I want to index this in all the existing entities. What I had to do is:

    @Override
    public void map(Entity value) {
        String property = "name";
        Object existingValue = value.getProperty(property);
        value.setIndexedProperty(property, existingValue);
        datastoreMutationPool.put(value);
    }
    

    Essentially, you will have to set the property as indexed property using setIndexedProperty(prop, value) and then save (put) the entity.

    I know I am very late in posting an answer. I thought I could help someone who might be struggling with this problem.

提交回复
热议问题