如何在elasticsearch中将位置设置为geo_point?

时间:2017-05-03 22:53:55

标签: elasticsearch geolocation logstash kibana geopoints

我遇到了failed to find geo_point field [location]

这个问题

这是我的流程。

  1. 导入csv

    input {
        file {
            path => "test.csv"
            start_position => "beginning"
            sincedb_path => "/dev/null"
        }
    }
    
    filter {
      csv {
        separator => ","
        #zip,lat, lon
        columns => [ "zip" , "lat", "lon"]
      }
    
      mutate {
        convert => { "zip" => "integer" }
        convert => { "lon" => "float" }
        convert => { "lat" => "float" }
      }
    
      mutate {
        rename => {
            "lon" => "[location][lon]"
            "lat" => "[location][lat]"
        }
      }
    
      mutate { convert => { "[location]" => "float" } }
    }
    
    output {
        elasticsearch {
            hosts => "cluster:80"
            index => "data"
        }
        stdout {}
    }
    
  2. 测试记录

    GET data
    
    "hits": [
    {
      "_index": "data",
      "_type": "logs",
      "_id": "AVvQcOfXUojnX",
      "_score": 1,
      "_source": {
        "zip": 164283216,
        "location": {
          "lon": 71.34,
          "lat": 40.12
        }
      }
    },
    ...
    
  3. 如果我尝试运行geo_distance查询,我会failed to find geo_point field [location]

    然后我尝试运行

    PUT data
    {
      "mappings": {
            "location": {
                "properties": {
                    "pin": {
                        "properties": {
                            "location": {
                                "type": "geo_point"
                            }
                        }
                    }
                }
            }
        }
    }
    

    但我得到index [data/3uxAJ4ISKy_NyVDNC] already exists

    如何将location转换为geo_point,以便我可以对其进行查询?

    编辑:

    我在索引任何内容之前尝试种植模板,但仍然存在相同的错误

    PUT _template/template
    {
      "template": "base_map_template",
      "order": 1,
      "settings": {
        "number_of_shards": 1
      },
      "mappings": {
        "node_points": {
          "properties": {
            "location": {
              "type": "geo_point"
            }
          }
        }
      }
    }
    

1 个答案:

答案 0 :(得分:0)

您需要为模板命名data而不是base_map_template,因为这是您的索引的命名方式。类型名称也必须是logs而不是node_points

PUT _template/template
{
  "template": "data",             <--- change this
  "order": 1,
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "logs": {                     <--- and this
      "properties": {
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}