写点什么

Elasticsearch Index Management 索引管理

用户头像
escray
关注
发布于: 2021 年 03 月 04 日
Elasticsearch Index Management 索引管理

Elasticsearch search scroll 游标查询,内容来自 B 站中华石杉 Elasticsearch 顶尖高手系列课程核心知识篇,英文内容来自 Elasticsearch: The Definitive Guide [2.x]

为什么要手动创建索引?


... you start wanting to fine-tune the indexing and search process to better suit your particular use case.


虽然 Elasticsearch 默认的动态索引可以很方便的使用,但是如果你希望根据业务需求对索引和查询的过程进行调优,那么就需要考虑进行索引管理。

创建索引 Creating an Index


... want to ensure that the index has been created with the appropriate number of primary shards, and that analyzers and mappings are set up before we index any data.


创建索引的语法


PUT /my_index{    "settings": { ... any settings ... },    "mappings": {        "type_one": { ... any mappings ... },        "type_two": { ... any mappings ... },        ...    }}
复制代码


number_of_shards: The number of primary shards, this setting cannot be changed after index creation.


number_of_replicas: The number of replica shards (copies) that each primary shard should have. This setting can be changed at any time on a live index.


可以在配置文件 config/elasticsearch.yml 中禁止自动创建索引:


action.auto_create_index: false
复制代码


创建索引的示例


PUT /my_index{  // one primary shard and no replica shards  "settings": {    "number_of_shards": 1,    "number_of_replicas": 0  },  "mappings": {    "my_type": {      "properties": {        "my_field": {          "type": "text"        }      }    }  }}
复制代码
修改索引


// change the number of replicaPUT /my_index/_settings{    "number_of_replicas": 1}
复制代码
删除索引 Deleting an Index


To delete an index:


DELETE /my_index
复制代码


Delete multiple indices:


DELETE /index_one,index_twoDELETE /index_*
复制代码


Delete all indices


DELETE /_allDELETE /*
复制代码


为了防止“删除跑路”,eliminate the possibility an accidental mass-deletion,可以在配置文件 elasticsearch.yml 中设置:


action.destructive_requires_name: true
复制代码


禁用 _all 和 通配符,避免误删。


发布于: 2021 年 03 月 04 日阅读数: 25
用户头像

escray

关注

Let's Go 2017.11.19 加入

在学 Elasticsearch 的项目经理

评论

发布
暂无评论
Elasticsearch Index Management 索引管理