Could someone explain the difference between an IndexRequest and an UpdateRequest for Elasticsearch? The javadoc for the UpdateRequest (class level) is blank and I can't find any documentaion for it.
I found some code that wraps an IndexRequest
inside an UpdateRequest
before adding it to a bulk operation, but I found that the BulkRequestBuilder
does not need the UpdateRequest
and can take an IndexRequest
directly, is there any advantage to doing this one way or the other?
IndexRequest indexRequest = new IndexRequest(indexName, typeName, docId)
.source(doc);
UpdateRequest updateRequest = new UpdateRequest(indexName, typeName, docId)
.doc(doc)
.upsert(indexRequest);
I have also observed that you can set the document timestamp on an IndexRequest
, but not on an UpdateRequest
. If the IndexRequest
is wrapped in an UpdateRequest
, and the doc is a new doc, then the timestamp will be written into Elasticsearch, but if the doc already exists, then the timestamp will be ignored and will be set to the current time. Is there any documentation anywhere that describes this behavior?
IndexRequest
defines the document to add to ElasticSearch, as opposed to UpdateRequest
which actually performs the addition into ElasticSearch.
Note: UpdateRequest.upsert()
expects a separate IndexRequest
to be used just if the document does not exist. This enables you to use a partial doc for cases where the doc already exists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With