LoginSignup
1
0

More than 5 years have passed since last update.

KinesisFirehose経由でElasticsearch@AWSに入力された緯度経度の値をgeo_point型として扱うには

Last updated at Posted at 2018-11-21

問題

KinesisFirehose経由でElasticsearchにデータを流す際にindex rotationの設定を行った場合、
指定したindex名にsuffixとしてhogehoge-2018-11-01 といったindex名が自動で作られていく。

スクリーンショット 2018-11-21 10.41.18.png

このときtypeがなければ作られるのだが、KinesisFirehoseから挿入されるデータが下記のようなgeo_pointの形式をちゃんと守っている場合でも

  "location": { 
    "lat": 41.12,
    "lon": -71.34
  }

kinesisFirehoseが自動でtypeを作ってしまうと、下記のような残念なmappingがされてしまう。

"location": {
  "properties": {
    "lat": {
      "type": "float"
    },
    "lon": {
      "type": "float"
    }
 }
},

理想形は下記。

"location": {
  "type": "geo_point"
},

対応方法

ElasticsearchのTemplate機能を使う。
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html

結局手動かよ!と思ってしまったが、Kibanaの可視化で緯度経度として扱えるのはメリットなので我慢

下記のようなjsonを用意して、

template.json

{
    "index_patterns": ["hogehoge-*"],
    "mappings": {
        "hogehoge_mapping": {
            "properties": {
                "location": {
                    "type": "geo_point"
                }
            }
        }
    }
}

ESのendpointに対し、template作成リクエストを行う。

curl -XPUT -H "Content-Type: application/json" 'https://your-domain.ap-northeast-1.es.amazonaws.com/_template/my_template' -d @temlate.json
1
0
1

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
1
0