【问题标题】:Changing elasticsearch index's shard-count on the next index-rotation在下一次索引轮换时更改弹性搜索索引分片计数
【发布时间】:2020-07-06 13:02:05
【问题描述】:

我有一个 ELK (Elasticsearch-Kibana) 堆栈,其中弹性搜索节点的默认分片值为 5。日志以 logstash 格式 (logstash-YYYY.MM.DD) 推送到它,如果我错了,请纠正我 - 已编入索引日期方面。

由于我无法在不重新索引的情况下更改现有索引的分片数,因此我想在创建下一个索引时将分片数增加到 8 个。我认为 ES-API 允许即时持久更改。

我该怎么做?

【问题讨论】:

    标签: elasticsearch logstash kibana


    【解决方案1】:

    您可以使用 Elasticsearch 中的“模板管理”功能:http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-templates.html

    使用以下命令创建新的 logstash 模板:

    curl -XPUT localhost:9200/_template/logstash -d '
    {
      "template": "logstash-*",
      "settings": {
        "number_of_replicas": 1,
        "number_of_shards": 8,
        "index.refresh_interval": "5s"
      },
      "mappings": {
        "_default_": {
          "_all": {
            "enabled": true
          },
          "dynamic_templates": [
            {
              "string_fields": {
                "match": "*",
                "match_mapping_type": "string",
                "mapping": {
                  "type": "string",
                  "index": "analyzed",
                  "omit_norms": true,
                  "fields": {
                    "raw": {
                      "type": "string",
                      "index": "not_analyzed",
                      "ignore_above": 256
                    }
                  }
                }
              }
            }
          ],
          "properties": {
            "@version": {
              "type": "string",
              "index": "not_analyzed"
            },
            "geoip": {
              "type": "object",
              "dynamic": true,
              "path": "full",
              "properties": {
                "location": {
                  "type": "geo_point"
                }
              }
            }
          }
        }
      }
    }'
    

    下次创建与您的模式匹配的索引时,它将使用您的新设置创建。

    【讨论】:

      【解决方案2】:

      该设置在您的弹性搜索中。您需要更改为配置文件config/elasticsearch.yml

      更改index.number_of_shards: 8。并重新启动弹性搜索。新配置将设置,新索引将使用新配置,根据需要创建 8 个分片。

      【讨论】:

      • 有什么方法可以通过 API 做到这一点?我不想丢失在重启期间进入的日志。
      • 您在logstash中使用哪个API来导入日志?你有使用redis吗?来自这个网站:elasticsearch.org/guide/en/elasticsearch/reference/current/… 没有任何 ES-API 可以在创建索引时更改分片数!
      • 根据 Rafi 的回答,使用模板是将更新的设置应用于新创建的索引的规范方法。
      【解决方案3】:

      最好是使用模板并添加一个我推荐的 Kopf pluin 在这里找到:https://github.com/lmenezes/elasticsearch-kopf

      您当然可以使用 API:

      curl -XPUT $ELASTICSEARCH-MASTER$:9200/_template/$TEMPLATE-NAME$ -d '$TEMPLATE-CONTENT$'
      

      在插件中:在左上角点击更多 -> 索引模板,然后创建一个新模板并确保您将以下设置作为模板的一部分:

      {
        "order": 0,
        "template": "logstash*",
        "settings": {
          "index": {
            "number_of_shards": "5",
            "number_of_replicas": "1"
          }
        },
        "mappings": {### your mapping ####},
        "aliases": {}
      }
      

      上述设置将确保如果创建一个名为 logstash* 的新索引,它将具有 5 个分片和 1 个副本。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-24
        • 1970-01-01
        • 2014-09-02
        • 1970-01-01
        相关资源
        最近更新 更多