Elasticsearch - 删除索引并重新创建索引

标签 elasticsearch

如果我删除包含一些数据的索引并立即使用以前的索引名称执行创建索引命令,然后将文档插入到以前的索引名称中,会发生什么情况?

Elasticsearch 能否保证以有序的方式处理数据,还是这个过程可能会弄乱数据?

最佳答案

这将按预期工作。我假设您担心删除数据会花费很长时间,并且您可能会在 Elasticsearch 完成删除旧索引之前重新创建相同的索引名称?

实际上,文件系统上不使用索引名称,而是为每个索引分配一个 UUID,用于存储(至少在 5.x 中)。请参阅 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

关于Elasticsearch - 删除索引并重新创建索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45228048/

相关文章:

elasticsearch - 空字段对Lucene索引有害吗?

indexing - 文本语料库遵循zipf定律的知识的优点是什么?

elasticsearch - 按日期 Elasticsearch

python - Elasticsearch 7.0 : filter must_not query error

elasticsearch - 通过多节点集群设置时无法访问Kibana中的elasticsearch实例

elasticsearch - Elasticsearch 索引和关系数据库中的索引有什么区别?

Elasticsearch 跨多个索引的单个分析器

elasticsearch - ElasticSearch Scroll API连接时间

c# - 如何格式化包含 html 的 Elasticsearch 高亮数据?

elasticsearch - 从具有唯一ID的组中返回具有最新时间戳的日志