Wish to search a closest person from input geo_point location . Quick steps to explain the requirement.
Steps : 1: Add documents with person name and their lat /long details
Expected result Request body shall contain geo_point (users lat /long location) ans shall search documents Closest to range (radius) e.g. 1: Search person added in #1 starting with 20 miles if found return matching documents 2: increase the offset by 5 miles ie. search person within 25 miles radius 3: repeat #2 till it reaches to max 50 miles in order to find a person
Add some sample data as below
PUT http://localhost:9200/person_locations/person/1
{
"name": "personA",
"location": {
"lat": 28.610001,
"lon": 77.230003
}
}
PUT http://localhost:9200/person_locations/person/2
{
"name": "personB",
"location" : {
"lat" : 28.610002,
"lon" : 77.230005
}
}
I am able to search location by specifying distance range e.g. 80 miles from given location .But If no persons found within the range Elastic search should find records by incrementing range by e.g. 10 miles (offset) so Elastic search should within 90 miles range and if still not found should return empty result set
GET http://localhost:9200/location_range_search1/_search
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "80mi",
"location": {
"lat" : 28.11,
"lon" : 77.11
}
}
}
}
}
}```