現象
fluentdを使ってApacheアクセスログをElasticsearch+kibanaへ流した際に
"host"や"path"、"agent"などの値が分かち書きされてしまう。
(Elasticsearchが全文検索をデフォルトとしているため、"/"などを区切り文字として分割してしまう)
対処
これを解決するにはElasticsearchのMapping設定をすればよい。
fluentdが以下設定だとしたら
<match **>
type elasticsearch
type_name apache_access
logstash_prefix apache_access
...
</match>
以下を実行して設定。
propertiesにどのキーを指定するかはお好みで。
curl -XPUT localhost:9200/_template/template_1 -d '
{
"template" : "apache_access-*",
"mappings" : {
"apache_access": {
"properties": {
"host" : { "type" : "string", "index" : "not_analyzed" },
"path" : { "type" : "string", "index" : "not_analyzed" },
"referer" : { "type" : "string", "index" : "not_analyzed" },
"domain" : { "type" : "string", "index" : "not_analyzed" },
"agent" : { "type" : "string", "index" : "not_analyzed" }
}
}
}
}
'