首页 文章

如何配置logstash以创建elasticsearch索引?

提问于
浏览
1

elasticsearch版本:elasticsearch-2.2.0.rpm logstash版本:logstash-2.2.2-1.noarch.rpm

我启动elasticsearch,然后使用具有基本stdin / stdout的/etc/logstash/conf.d/logstash.conf进行logstash,但不创建弹性搜索索引 . 如果我将以下内容添加到我的logstash输出配置中,我会得到一个指示黄色状态的索引:

action =>“create”index =>“main_index”

它是黄色的,不可用的原因是因为分片的数量是5,副本是3.如果我运行:

curl -XPUT'http://localhost:9200/index2/ ' -d ' index:number_of_shards:1 number_of_replicas:0'

“index2”是绿色且可用的 . 我如何告诉logstash和/或elasticsearch我希望我的索引在没有发出curl命令的情况下拥有1个具有0个副本的分片?

谢谢 .

3 回答

  • 0

    为了完成Val´s answer,这是ES版本5.x的更新:

    解决方案3无法正常工作,因为配置文件禁用了索引级别配置:“由于弹性搜索5.x索引级别设置无法在节点配置上设置,如elasticsearch.yaml”

    解决方案1确实有效,下面是一个例子:

    • here下载并编辑ES 5.x的基本模板 .

    • 更改模板名称以匹配索引名称模式,并首先添加要更新的索引设置:

    {
      "template" : "syslog*",
      "version" : 50001,
      "settings" : {
       "index.refresh_interval" : "5s",
       "index.number_of_replicas" : 0,
       "index.number_of_shards" : 1
      },
    ...
    }
    
    • 更新logstash配置,以便输出使用创建的模板:
    output {
      elasticsearch {
        hosts => ["localhost:9200"]
        index => "syslog%{+YYYY.MM.dd}"
        template => "path_to_your_template.json"
        template_name => "syslog*"
        template_overwrite => true
      }
    }
    
    • 重启服务
  • 3

    例如,您可以使用以下请求创建一个小索引 - 只有一个主分片 - 而不是副本分片:

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

    你有三个解决方案:

    • 您覆盖Logstash使用的default index template,并使用正确的设置provide your own,即使用 "number_of_replicas": 0

    • 使用正确的索引设置在ES中创建index template

    • elasticsearch.yml 中,更改名为 index.number_of_replicas 的设置并将其设置为0(然后重新启动ES)

相关问题