前端开发入门到精通的在线学习网站

网站首页 > 资源文章 正文

ElasticSearch系列-索引创建

qiguaw 2024-12-31 14:00:50 资源文章 14 ℃ 0 评论

引文

开启自动创建索引配置

# 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 索引映射


Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表