I am trying to fetch all the documents within a radius of a particular location (lat,long). Here's the mapping with location as the geo_point:
{
"mappings": {
"_doc": {
"properties": {
"color": {
"type": "long"
},
"createdTime": {
"type": "date"
},
"location": {
"properties": {
"lat": {
"type": "float"
},
"lon": {
"type": "float"
}
}
}
}
}
}
}
And here's my query
{
"aggregations": {
"weather_agg": {
"geo_distance": {
"field": "location",
"origin": "41.12,-100.77",
"unit": "km",
"distance_type": "plane",
"ranges": [
{
"from": 0,
"to": 100
}
]
},
"aggregations": {
"timerange": {
"filter": {
"range": {
"createdTime": {
"gte": "now-40h",
"lte": "now"
}
}
},
"aggregations": {
"weather_stats": {
"stats": {
"field": "color"
}
}
}
}
}
}
}
}
I am getting 0 hits for this. My question is whether there's something wrong with the mapping or the query ? We recently migrated to a newer cloud version and there's a possibility that something broke because of that.
Instead of mapping lat
and long
as float you should geo-point mapping