flume/elasticsearch创建新索引并忽略显式创建的索引

kcugc4gi  于 2021-06-04  发布在  Flume
关注(0)|答案(1)|浏览(408)

我们在elasticsearch中创建了一个索引,索引名为apachelog,动态Map设置为“strict”,我们将httpresponse字段设置为type 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"}
    }
  }
}'

我们的flume elasticsearch接收器配置如下,请注意索引名称与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使用我们的索引而不是创建自己的索引?

zaq34kh6

zaq34kh61#

FlumeelasticsearchFlume的行为与其默认行为相同。它根据utc时间戳写入索引名。这就是kibana工具将要寻找的。
例如,可以将索引名称格式更改为“写入每月索引”而不是“每日索引”。我不记得我们离开的时候有没有时间。
我建议您可能不想为所有事件都使用一个索引。当es变得庞大时,它将开始出现问题,而您将无法采取任何措施来更改复制或分片因子。这是graylog在只有一个索引时的经历。
由于您似乎想要配置字段类型,我建议您查看索引模板,并为apachelog*添加一个您想要的模板。然后删除旧索引,并让es在该模板之后创建一个索引。

相关问题