ES modifies the index structure

Original link: https://jasonkayzk.github.io/2022/06/22/ES%E4%BF%AE%E6%94%B9%E7%B4%A2%E5%BC%95%E7%BB%93 %E6%9E%84/

Sometimes we need to modify the index information when using ES;

This article summarizes how to modify index information;

ES modifies the index structure

Indexing in ElasticSearch is similar to the concept of Table in relational databases;

If you want to modify some key information of the index, rebuild the index;

Specific steps are as follows:

  • new index;
  • copy data (reindex);
  • confirm data;
  • delete old aliases;
  • delete old indexes;
  • Create aliases (aliases);

Suppose the index name we use is test , which is implemented by using index aliases;

First we have the test_v1 index, now we need to rebuild the index to test_v2 ;

Here is an example script:

 # 创建V2版本索引curl -u <user>:<passwd> -XPUT -H "Content-Type: application/json" 'http://<ip>:9200/test_v2' -d '{"settings":{ ... }}'# 复制数据(reindex)curl -u <user>:<passwd> -XPOST -H "Content-Type: application/json" 'http://<ip>:9200/_reindex' -d '{"source":{"index":"test_v1"},"dest":{"index":"test_v2"}}'# 查看V2版本索引下文档数量curl -u <user>:<passwd> -XGET -H "Content-Type: application/json" 'http://<ip>:9200/_cat/count/test_v2?v' -d '{}'# 删除V1版本到索引test的索引别名curl -u <user>:<passwd> -XDELETE -H "Content-Type: application/json" 'http://<ip>:9200/test_v1/_aliases/test'# 删除V1版本索引curl -u <user>:<passwd> -XDELETE -H "Content-Type: application/json" 'http://<ip>:9200/test_v1'# 创建V2版本索引到test索引curl -u <user>:<passwd> -XPUT -H "Content-Type: application/json" 'http://<ip>:9200/test_v2/_aliases/test'

appendix

Reference article:

This article is reprinted from: https://jasonkayzk.github.io/2022/06/22/ES%E4%BF%AE%E6%94%B9%E7%B4%A2%E5%BC%95%E7%BB%93 %E6%9E%84/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment