Elasticsearch-索引设置settings

前言

本文基于elasticsearch7.3.0版本
Elasticsearch-索引设置settings_第1张图片

settings主要设置

settings部分主要包括:分片数,副本数,刷新间隔,分析器

PUT index_test
{
    "settings":{
    	// 设置索引分片数,默认为1,只能在创建索引时设置,之后任何时候都不能修改
    	"number_of_shards": 3,
    	// 设置索引分片副本数,默认为1,之后可以任意修改
    	"number_of_replicas": 1,
    	// 刷新间隔,默认1s,近实时,文档从索引到可以被检索中间间隔就是这个值
    	"refresh_interval": "1s",
    	// 分析器
        "analysis":{
            "analyzer":{
            	// 自定义分析器
                "ik_pinyin_analyzer":{
                    "type":"custom",
                    "char_filter":[
                        "emoticons"
                    ],
                    "tokenizer":"ik_max_word",
                    "filter":[
                        "pinyin_filter"
                    ]
                }
            },
            // 字符过滤器
            "char_filter":{
                "emoticons":{
                    "type":"mapping",
                    "mappings":[
                        ":) => _happy_",
                        ":( => _sad_"
                    ]
                }
            },
            // 分词器
            "tokenizer":{
                "punctuation":{
                    "type":"pattern",
                    "pattern":"[ .,!?]"
                }
            },
            // token过滤器
            "filter":{
                "pinyin_filter":{
                    "type":"pinyin",
                    "keep_original":true
                }
            }
        }
    }
}

查看索引settings

# 请求
GET index_test/_settings

# 响应
{
  "index_test" : {
    "settings" : {
      "index" : {
        "refresh_interval" : "1s",
        "number_of_shards" : "3",
        "provided_name" : "index_test",
        "creation_date" : "1576394655937",
        "analysis" : {
          "filter" : {
            "pinyin_filter" : {
              "type" : "pinyin",
              "keep_original" : "true"
            }
          },
          "char_filter" : {
            "emoticons" : {
              "type" : "mapping",
              "mappings" : [
                ":) => _happy_",
                ":( => _sad_"
              ]
            }
          },
          "analyzer" : {
            "ik_pinyin_analyzer" : {
              "filter" : [
                "pinyin_filter"
              ],
              "char_filter" : [
                "emoticons"
              ],
              "type" : "custom",
              "tokenizer" : "ik_max_word"
            }
          },
          "tokenizer" : {
            "punctuation" : {
              "pattern" : "[ .,!?]",
              "type" : "pattern"
            }
          }
        },
        "number_of_replicas" : "1",
        "uuid" : "xJZY4_EeQqm5_0ooTW2Pbw",
        "version" : {
          "created" : "7030099"
        }
      }
    }
  }
}

动态修改索引副本数

PUT index_test/_settings
{
  "number_of_replicas": 2
}

修改刷新时间

PUT index_test/_settings
{
  "settings": {
    "index": {
      "refresh_interval":"30s"
    }
  }
}

你可能感兴趣的:(ElasticSearch,elasticsearch)