Elasticsearch 索引设定

示例

索引设置是应用于单个索引的那些设置。此类设置将以开头index.。该规则的例外是number_of_shards和number_of_replicas,并且也以index.number_of_shards和的形式存在index.number_of_replicas。

顾名思义,索引级设置适用于单个索引。有些设置必须在创建时应用,因为它们不能动态更改,例如index.number_of_shards,用于控制索引的主分片数量的设置。

PUT /my_index
{
  "settings": {
    "index.number_of_shards": 1,
    "index.number_of_replicas": 1
  }
}

或者,以更简洁的格式,您可以在每个位置组合键前缀.:

PUT /my_index
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 1
    }
  }
}

上面的示例将使用提供的设置创建索引。您可以使用索引_settings端点动态更改每个索引的设置。例如,在这里我们针对警告级别动态更改慢速日志设置:

PUT /my_index/_settings
{
  "index": {
    "indexing.slowlog.threshold.index.warn": "1s",
    "search.slowlog.threshold": {
      "fetch.warn": "500ms",
      "query.warn": "2s"
    }
  }
}

警告:Elasticsearch 1.x并2.x没有非常严格地验证索引级设置名称。如果您有错字,或者只是简单地编排了一个设置,则它会盲目接受它,否则会忽略它。Elasticsearch 5.x严格验证设置名称,它将拒绝任何尝试使用未知的索引设置setting(s)(由于拼写错误或缺少插件)的尝试。这两个语句都适用于动态更改索引设置以及在创建时。