I am getting latitude and longitude values from a rest API and i want to create a location object in groovy/java(may be using double arrays) and store it to Elasticsearch with other parameters. I know how to do this through logstash and wondering how to achieve it from groovy/java..
how to created the below object using groovy/java.
"location": {
"lat": "50.68262437",
"lon": "7.5592885"
}
Thanks in advance!!
Just create a Groovy map. It'll be serialized to a JSON object with lat and lon properties.
def location = [
lat: "50.68262437",
lon: "7.5592885"
]
(Although I suspect the lat/lon values should be floating point values and not strings.)
Thanks Mangus,
I got it, it was not as difficult as i thought.
here is my experience
2 things to take care.
- in My Java class I have created a GeoPoint object like this..
GeoPoint location = new GeoPoint(lat,lon)
// latitude(lat) and longitude(long) values are double values.
- Map the location object as below in Elasticsearch
"mappings": {
"properties": {
"location": {
"type": "geo_point"
}
}
}