J.Done
J.Done

Reputation: 3053

Elasticsearch - Delete index and re-create index

What will happen if I delete an index that has some data and immediately execute the create index command using the previous index name and then I insert a document to that previous index name?

Will Elasticsearch guarantee to process the data in an orderly fashion or will this process possibly mess up the data?

Upvotes: 2

Views: 6170

Answers (1)

xeraa
xeraa

Reputation: 10859

This will work as expected. I assume you are concerned that the deletion of the data will take a long time and you might recreate the same index name before Elasticsearch finished removing the old one?

Actually, index names are not used on the filesystem and every index gets assigned a UUID instead, which is used for storage (at least in 5.x). See the following example on 5.5.0:

$ curl -XPUT -u "elastic:changeme" localhost:9200/test
{"acknowledged":true,"shards_acknowledged":true}

$ curl -XGET -u "elastic:changeme" localhost:9200/_cat/indices/test?v
health status index uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   test  lwk6SME0SGaits-l2Y-DJg   5   1          0            0       810b           810b

$ ls /var/lib/elasticsearch/nodes/0/indices/lwk6SME0SGaits-l2Y-DJg/
0/      1/      2/      3/      4/      _state/ 

$ curl -XDELETE -u "elastic:changeme" localhost:9200/test
{"acknowledged":true}

$ curl -XPUT -u "elastic:changeme" localhost:9200/test
{"acknowledged":true,"shards_acknowledged":true}

$ curl -XGET -u "elastic:changeme" localhost:9200/_cat/indices/test?v
health status index uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   test  cCJAB5i-Qjes7OUUo1m63w   5   1          0            0       810b           810b

$ ls /var/lib/elasticsearch/nodes/0/indices/cCJAB5i-Qjes7OUUo1m63w/
0  1  2  3  4  _state

$ ls /var/lib/elasticsearch/nodes/0/indices/lwk6SME0SGaits-l2Y-DJg/
ls: cannot access '/var/lib/elasticsearch/nodes/0/indices/lwk6SME0SGaits-l2Y-DJg/': No such file or directory

Upvotes: 4

Related Questions