user1213178
user1213178

Reputation: 61

Updating document and adding new field in elastic search

We have usecase that data will be updated daily. Some of attributes of document changes and some of new record is there. Is it possible to reindex data with updated value, which is already there and add new reocord. if yes, please explain how.

Is it with update API?

I am indexing like this

 String json = getJsonMapper().writeValueAsString(data);
    bulkRequestBuilder.add(getClient().prepareIndex(indexName, typeName).setSource(json));

I am not passing any id. How can i update this. What is best way

Upvotes: 1

Views: 1538

Answers (1)

Alkis Kalogeris
Alkis Kalogeris

Reputation: 17773

Elasticsearch uses Apache Lucene underneath the covers. In Lucene documents are immutable.

You can use the Update API for your use case. This API does a delete and save underneath but that doesn't concern you. You can even update a part of the document, which means that Elasticsearch will retrieve the old document, generate the new one, delete the old one and save the new one.

The problem is that for all this to work is that you need to use the same id. If you don't then Elasticsearch will generate one for you if you use the Index API. This means that it will be saved as a new document. The Update API needs the id, otherwise it doesn't know what to update.

Upvotes: 2

Related Questions