Elasticsearch: difference between IndexRequest and UpdateRequest

Can someone explain the difference between IndexRequest and UpdateRequest for Elasticsearch? The javadoc for UpdateRequest (class level) is empty and I cannot find the documentation for it.

I found some code that wraps IndexRequestinside UpdateRequestbefore adding it to the bulk operation, but I found that it BulkRequestBuilderdoesn’t need UpdateRequestand can take IndexRequestdirectly, is there any advantage for this anyway?

IndexRequest indexRequest = new IndexRequest(indexName, typeName, docId)
    .source(doc);
UpdateRequest updateRequest = new UpdateRequest(indexName, typeName, docId)
    .doc(doc)
    .upsert(indexRequest);

I also noticed that you can set the document timestamp on IndexRequest, but not on UpdateRequest. If IndexRequestenclosed in UpdateRequest, and doc is a new document, then the timestamp will be written to Elasticsearch, but if the document already exists, the timestamp will be ignored and set to the current time. Is there any documentation anywhere that describes this behavior?

+4
source share

Source: https://habr.com/ru/post/1616108/


All Articles