LoginSignup
27
29

More than 5 years have passed since last update.

fluentd -> elasticsearchでつっこんだデータのstringになっているやつをintegerに変換する

Last updated at Posted at 2014-05-14

[2015/08/25]追記

この方法では一時的にそのindexではうまくいきますが、fluentdから送られるデータは変わっておらず、新しいindexを作成するタイミングでまた同じ状況になってしまいます。
下記が現状での正しい対処法です。
Elasticsearchでintegerになっていて欲しいところがstringになっていた時の対処法 - Qiita

概要

fluentd + elasticsearch + kibanaを作成して、apacheのlatencyでsortしようとしたら、なんか上手くいかない。latencyがstringではいっていることに気づいた。

確認法

$ curl -X GET localhost:9200/apache_access-201405/access_log/_mapping?pretty=true
{
  "apache_access-201405" : {
    "mappings" : {
      "access_log" : {
        "properties" : {
          "@timestamp" : {
            "type" : "date",
            "format" : "dateOptionalTime"
          },
          "X-Forwarded-For" : {
            "type" : "string"
          },
          "agent" : {
            "type" : "string"
          },
          "host" : {
            "type" : "string"
          },
          "latency" : {
            "type" : "string"
          },
          "referer" : {
            "type" : "string"
          },
          "request" : {
            "type" : "string"
          },
          "size" : {
            "type" : "string"
          },
          "status" : {
            "type" : "string"
          }
        }
      }
    }
  }
}

解決法

いろいろと調査をした結果、templateというものを設定する必要があるらしい。
Elasticsearch の index templates で解析方法を指定する(または、default mapping が効かない時に) - Qiita

$ curl -XPUT localhost:9200/_template/accesslog -d '
{
  "template": "apache_access-*",
  "mappings": {
    "access_log":{
      "properties":{
        "latency":{
          "type":"integer"
        }
      }
    }
  }
}
'

こういう感じに設定される

$ curl -XGET localhost:9200/_template/
{"accesslog":{"order":0,"template":"apache_access-*","settings":{},"mappings":{"access_log":{"properties":{"latency":{"type":"integer"}}}},"aliases":{}}}

即反映されなかった(よくわからなかった)ため、いったんindexを削除して作りなおしたりした。

27
29
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
29