Skip to content

Instantly share code, notes, and snippets.

@djptek
Created March 13, 2019 08:46
Show Gist options
  • Save djptek/eb69d272d1c928ae01a74497aa7b4330 to your computer and use it in GitHub Desktop.
Save djptek/eb69d272d1c928ae01a74497aa7b4330 to your computer and use it in GitHub Desktop.
Looking at incrementing version after delete
# add a test doc
$ curl -X PUT server1:9200/test1/_doc/1 -H 'Content-Type: application/json' -d '{}'
{"_index":"test1","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
#delete the test doc, get a 200
$ curl -I -X DELETE server1:9200/test1/_doc/1
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 153
# delete a few more times, _version is incremented
$ curl -X DELETE server1:9200/test1/_doc/1
{"_index":"test1","_type":"_doc","_id":"1","_version":3,"result":"not_found","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":2,"_primary_term":1}
curl -X DELETE server1:9200/test1/_doc/1
{"_index":"test1","_type":"_doc","_id":"1","_version":4,"result":"not_found","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":3,"_primary_term":1}
etc...
# delete again but this time look at the status code, not the response
$ curl -I -X DELETE server1:9200/test1/_doc/1
HTTP/1.1 404 Not Found
content-type: application/json; charset=UTF-8
content-length: 155
# so it has gone...
# now, expunge
curl -X POST server1:9200/_forcemerge?only_expunge_deletes=false\&max_num_segments=100\&flush=true
{"_shards":{"total":61,"successful":31,"failed":0}}
# try the delete again, now version is 1
$ curl -X DELETE server1:9200/test/_doc/1
{"_index":"test","_type":"_doc","_id":"1","_version":1,"result":"not_found","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":43,"_primary_term":2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment