引文

开启自动创建索引配置

# config/ElasticSearch.yml -- 配置文件 action.auto_create_index: false -- 设置是否开启自动创建索引

一、动态映射创建索引

PUT test -- 结果 { "acknowledged" : true, "shards_acknowledged" : true, "index" : "test" }

二、手动创建索引

我们需要确保索引被创建在适当数量的分片上,在索引数据_之前_设置好分析器和类型映射。

为了达到目标,我们需要手动创建索引,在请求中加入所有设置和类型映射,如下所示:

PUT /my_index { "settings": { ... any settings ... }, "mappings": { "type_one": { ... any mappings ... }, "type_two": { ... any mappings ... }, ... } } put /test { "settings":{ "number_of_shards":3, "number_of_replicas":2 }, "mappings":{ "properties":{ "id":{"type":"long"}, "name":{"type":"text","analyzer":"ik_smart"}, "text":{"type":"text","analyzer":"ik_max_word"} } } }

参数介绍

number_of_shards 分片数

number_of_replicas 备份数

mappings 索引映射


elasticsearch 索引创建性能(ElasticSearch系列-索引创建)(1)

,