我们在 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 使用我们的索引而不是创建自己的索引吗?