【问题标题】:Default elasticsearch configuration for docker containerdocker 容器的默认 elasticsearch 配置
【发布时间】:2016-02-13 01:19:18
【问题描述】:

在 docker 容器中使用映射配置 ES 索引模板的最佳方法是什么?我希望使用模板文件,但似乎从第 2 版开始它is not possible。执行 http 请求也不起作用,因为容器创建过程没有启动。它可以在每次容器启动时使用脚本来完成,该脚本将启动 ES 并向其执行 HTTP 请求,但它看起来真的很难看。

【问题讨论】:

  • @mavarazy,不。我在容器启动时使用 HTTP API

标签: elasticsearch docker


【解决方案1】:

您可以通过在 Linux 终端中执行 HTTP PUT 请求来配置带有映射的模板,如下所示:

curl -XPUT http://ip:port/_template/logstash -d '
    {
      "template": "logstash-*",
      "settings": {
        "number_of_replicas": 1,
        "number_of_shards": 8
      },
      "mappings": {
        "_default_": {
          "_all": {
            "store": false
          },
          "_source": {
            "enabled": true,
            "compress": true
          },
          "properties": {
            "_id": {
              "index": "not_analyzed",
              "type": "string"
            },
            "_type": {
              "index": "not_analyzed",
              "type": "string"
            },
            "field1": {
              "index": "not_analyzed",
              "type": "string"
            },
            "field2": {
              "type": "double"
            },
            "field3": {
              "type": "integer"
            },
            "xy": {
              "properties": {
                "x": {
                  "type": "double"
                },
                "y": {
                  "type": "double"
                }
              }
            }
          }
        }
      }
    }
    '

“logstash-*”是你的索引名,你可以试试。

【讨论】:

    【解决方案2】:

    如果使用 logstash,您可以将模板作为 logstash 管道配置的一部分

    管道/logstash.conf

    input {
        ...
    }
    
    filter {
        ...
    }
    
    output {
        elasticsearch {
            hosts => "elasticsearch:9200"
            template => "/usr/share/logstash/templates/logstash.template.json"
            template_name => "logstash"
            template_overwrite => true
            index => "logstash-%{+YYYY.MM.dd}"
        }
    }
    

    参考:https://www.elastic.co/guide/en/logstash/6.1/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-template

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 2016-08-21
      • 1970-01-01
      • 1970-01-01
      • 2014-11-27
      • 1970-01-01
      相关资源
      最近更新 更多