首页 文章

如何在logstash中映射位置(lon,lat)以在kibana中可视化?

提问于
浏览
0

我有一个csv文件,保存一些记录的经度和纬度(否则它是“”) . 现在我想使用logstash 5.1.2将数据转换为elasticsearch 5.1.2 . 我编写了以下配置文件,但位置字段仍然映射到文本 .

input {  
      file {
            path => "/usr/local/Cellar/logstash/5.1.2/bin/data.csv"
            start_position => "beginning"
            sincedb_path => "/dev/null"
      }
}

filter {  
    csv {
        columns => ['logtime', 'text', 'user', 'country', 'location']
        separator => ","
    }
    date {
        match => ["logtime", "yyyy-MM-dd HH:mm:ss"]
        timezone => "Europe/London"
        target => "Date"
    }
    if [latitude] and [longitude] {
    mutate { convert => {"latitude" => "float"} }
    mutate { convert => {"longitude" => "float"} }
    mutate { rename => {"latitude" => "[location][lat]"} }
    mutate { rename => {"longitude" => "[location][lon]"} }
    }
}

output {
  elasticsearch { 
    hosts => ["localhost:9200"] 
    index => "twitter"}
}

我应该做些什么来使位置字段映射为地理点,并能够在Kibana 5.1.2中可视化 Map 上的点?谢谢

1 回答

  • 3

    您需要创建将 location 映射到geo_point的映射 . 最简单的方法是使用索引模板,这样当您开始使用基于时间的索引时,它将在创建新索引时自动创建映射 .

    PUT /_template/twitter
    {
      "order": 0,
      "template": "twitter*",
      "mappings": {
        "_default_": {
          "properties": {
            "location": {
              "type": "geo_point"
            }
          }
        }
      }
    }
    

    然后删除 /twitter 索引并重新索引数据 .

    上面的模板说任何使用名称 twitter* 创建的索引都会将 _typelocation 字段变成 geo_point .

相关问题