1、新建索引
[新建索引]:
curl --request PUT \
--url http://127.0.0.1:9200/searchindex20231213143924 \
--header 'content-type: application/json' \
--data '{"settings":{"index":{"analysis":{"analyzer":{"default":{"tokenizer":"index_ansj"}}}}}}'
其中:
data:指定分词器。我上面写的仅是测试用的,不是标准。
执行返回:
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "searchindex20231213143924 "
}
代表成功。也可以访问 http://127.0.0.1:9200/_cat/indices?v 看看新建的索引是否存在了。
2、执行数据迁移
[迁移数据]:
curl --request POST \
--url 'http://127.0.0.1:9200/_reindex?wait_for_completion=false' \
--header 'content-type: application/json' \
--data '{"source":{"index":"searchindex20231213143924"}, "dest":{"index":"searchindex20240112203224"}}'
其中:
source:代表原索引,dest:代表目标索引。
3、更改别名指向
[查看别名]:
curl --request GET \
--url http://127.0.0.1:9200/_cat/aliases
[删除别名]:
curl --request POST \
--url http://127.0.0.1:9200/_aliases \
--header 'content-type: application/json' \
--data '{"actions":[{"remove":{"index":"searchindex20231213143924","alias":"searchindex"}}]}'
[指定别名]:
curl --request POST \
--url http://127.0.0.1:9200/_aliases \
--header 'content-type: application/json' \
--data '{"actions":[{"add":{"index":"searchindex20240112203224","alias":"searchindex"}}]}'