There is an index with this mapping:
"data": {
"type": "object"
},
"modified_date": {
"type": "date"
},
"uid": {
"type": "keyword"
}
Now I want to do a bulk operation for upsert (Update if exists and insert if not exists). The query is on uid
field. I wrote this query but its not working.
URL : http://host/index/_bulk
METHOD : POST
DATA :
{"update":{"uid":"123"}}
{"doc":{"modified_date":"...", "data":{"array":[1,2,3]}}, "doc_as_upsert":true}
{"update":{"uid":"456"}}
{"doc":{"modified_date":"...", "data":{"array":[4,5,6]}}, "doc_as_upsert":true}
{"update":{"uid":"789"}}
{"doc":{"modified_date":"...", "data":{"array":[7,8,9]}}, "doc_as_upsert":true}
How can I do bulk upsert with query on uid
field?
If you change operation from
update
toinsert
, you'd be upserting.https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html