简体   繁体   中英

How to setup location as a geo_point in elasticsearch?

I've been running into this issue where I get failed to find geo_point field [location]

Here is my flow.

  1. Import 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. Test records

     GET data "hits": [ { "_index": "data", "_type": "logs", "_id": "AVvQcOfXUojnX", "_score": 1, "_source": { "zip": 164283216, "location": { "lon": 71.34, "lat": 40.12 } } }, ... 

If I try to run a geo_distance query I get failed to find geo_point field [location]

Then I try to run

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

but I get index [data/3uxAJ4ISKy_NyVDNC] already exists

How to I convert location into a geo_point so I can run the query on it?

edit:

I tried planting a template before i index anything, but still same errors

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

You need to name your template data instead of base_map_template since this is how your index is named. Also the type name needs to be logs instead of 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"
        }
      }
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM