Flume / Elasticsearch创建新索引并忽略显式创建的索引

时间:2015-09-09 15:09:53

标签: curl indexing elasticsearch flume log-analysis

我们在Elasticsearch中创建了一个索引如下,索引名称是apachelog,动态映射设置为“strict”,我们将httpresponse字段设置为integer:

curl -X PUT 'http://localhost:9200/**apachelog**' -d \
'{
  "log": {
<b>"dynamic": "strict"</b>,
    "properties": {
      "@fields": {
        "properties": {
          "agent": {"type": "string"},
          "city": {"type": "string"},
          "client_ip": {"type": "string"},
          "hitTime": {"type": "string"},
          "host": {"type": "string"},
          <b>"httpresponse": {"type": "integer"}</b>
        }
      },
      "@message": {"type": "string"},
      "@source_host": {"type": "string"},
      "@timestamp": {"type": "date", "format": "dateOptionalTime"}
    }
  }
}'

我们的水槽ElasticSearch接收器配置如下,请注意索引名称 apachelog 与已在ES中创建的索引相同:

写入ElasticSearch

collector.sinks.elasticsearch.type =          org.apache.flume.sink.elasticsearch.ElasticSearchSink
collector.sinks.elasticsearch.channel = mc2
collector.sinks.elasticsearch.batchSize=100
collector.sinks.elasticsearch.hostNames = localhost:9300
collector.sinks.elasticsearch.indexName = apachelog
collector.sinks.elasticsearch.clusterName = logsearch
collector.sinks.elasticsearch.serializer =    org.apache.flume.sink.elasticsearch.ElasticSearchLogStashEventSerializer

现在,当我们启动并运行flume代理时,我们注意到在ElasticSearch中创建了一个名为 apachelog-2015-09-09 的新索引以及字段 httpresponse的数据类型字符串。我们注意到Flume / ES正在向新创建的索引添加文档,而我们使用名称apachelog显式创建的索引处于休眠状态。

知道为什么会这样,以及我们如何让Flume / ES使用我们的索引而不是创建自己的索引?

1 个答案:

答案 0 :(得分:0)

Flume Elasticsearch Sink的行为与其默认行为相同。它根据UTC时间戳写入索引名称。这就是Kibana工具将要寻找的东西。

您可以将索引名称格式更改为,例如,写入每月索引而不是每日。我不记得我们是否留下了没有时间组件的方式。

我建议您可能不希望所有活动都有一个索引。当ES变得庞大并且您无法做任何改变复制或分片因素的任何事情时,ES将开始出现问题。这是GrayLog拥有单一索引时的体验。

由于您似乎想要配置字段类型,我建议您查看索引模板并为apachelog *添加一个可以执行您想要的操作。然后删除旧索引,让ES在该模板后面创建一个索引。

相关问题