【问题标题】:Flume / Elasticsearch creating a new index and ignoring the index explicitly createdFlume / Elasticsearch 创建新索引并忽略显式创建的索引
【发布时间】:2023-03-05 06:05:01
【问题描述】:

我们在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 的数据类型的新索引字符串。我们注意到 Flume/ES 正在向新创建的索引添加文档,而我们显式创建的名为 apachelog 的索引处于休眠状态。

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

【问题讨论】:

    标签: curl indexing elasticsearch flume log-analysis


    【解决方案1】:

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

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

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

    由于您似乎想要配置字段类型,我建议您查看索引模板并为 apachelog* 添加一个您想要的。然后删除旧的索引,让 ES 按照那个模板创建一个索引。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-30
      • 2011-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-06
      • 1970-01-01
      相关资源
      最近更新 更多