MongoDB Elasticsearch mapping to geopoint

2019-09-09 23:09发布

问题:

I'm trying to get Kibana to see my location info as a geo_point. I've been running about mapping and how to do it, but I can't seem to figure it out. The data looks like this in mongodb:

{ "_id" : "3", "loc" : "[-122.0574, 37.41919999999999]", "fs" : "Clean", "name" : "www.googleapis.com", "timestamp" : "2016-07-02T21:02:53.623Z", "destination" : "192.168.79.136", "source" : "216.58.212.138", "vt" : "0" }

How would I map the values that are stored in the key "loc" as geo_point?

回答1:

In mongoDB the first value is longitude and the next is latitude.You can add a geo point data type to your elasticsearch mapping.

PUT my_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "loc": {
          "type": "geo_point"
        }
      }
    }
  }
}

And when you add data,

PUT my_index/my_type/3
{
  "loc": { 
    "lat": 37.41919999999999,
    "lon": -122.0574
  }
}

Refer to this