1

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

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"}
    }
  }
}'

我们的flume ElasticSearch sink配置如下,注意索引名称是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的数据类型是string。我们注意到 Flume/ES 正在向新创建的索引添加文档,而我们显式创建的名为 apachelog 的索引处于休眠状态。

知道为什么会发生这种情况以及我们如何让 Flume/ES 使用我们的索引而不是创建自己的索引吗?

4

1 回答 1

0

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

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

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

当您似乎想要配置字段类型时,我建议您查看索引模板并为 apachelog* 添加一个,它可以满足您的需求。然后删除旧的索引,让 ES 按照那个模板创建一个索引。

于 2015-09-11T18:14:58.810 回答