Skip to content

Instantly share code, notes, and snippets.

@paul-butcher
Created July 7, 2022 10:59
Show Gist options
  • Save paul-butcher/6dc2f456e041c61221ca4167a3d376da to your computer and use it in GitHub Desktop.
Save paul-butcher/6dc2f456e041c61221ca4167a3d376da to your computer and use it in GitHub Desktop.
Elasticsearch _bulk NOOP
This fails, you cannot update something that is not there
{"update": {"_index":"banana","_id":"dolly"}}
{"doc": {"hello":"dolly"}}
This succeeds, but will always update, even if unchanged.
The version count will increase, and the value of "result" will be "updated"
{"index": {"_index":"banana","_id":"kitty"}}
{"doc": {"hello":"kitty"}
This will insert or update as appropriate. If there are no changes, the value of "result" will be "noop"
{"update": {"_index":"banana","_id":"world"}}
{"doc": {"hello":"world"}, "doc_as_upsert": true}
curl -XPUT localhost:9200/banana
curl -XPOST localhost:9200/banana/_bulk -H Content-Type:application/x-ndjson --data-binary "@update"
{"update": {"_index":"banana","_id":"dolly"}}
{"doc": {"hello":"dolly"}}
{"update": {"_index":"banana","_id":"world"}}
{"doc": {"hello":"world"}, "doc_as_upsert": true}
{"index": {"_index":"banana","_id":"kitty"}}
{"doc": {"hello":"kitty"}, "doc_as_upsert": true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment