You are looking at documentation for an older release.
Not what you want? See the
current release documentation.
Upsertedit
There is also support for upsert. If the document does not already exists, the content of the upsert
element will be used to index the fresh doc:
IndexRequest indexRequest = new IndexRequest("index", "type", "1")
.source(jsonBuilder()
.startObject()
.field("name", "Joe Smith")
.field("gender", "male")
.endObject());
UpdateRequest updateRequest = new UpdateRequest("index", "type", "1")
.doc(jsonBuilder()
.startObject()
.field("gender", "male")
.endObject())
.upsert(indexRequest);
client.update(updateRequest).get();If the document index/type/1 already exists, we will have after this operation a document like:
If it does not exist, we will have a new document:
{
"name" : "Joe Smith",
"gender": "male"
}