Incremental search on geo_point

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
                    }
                }
            }
        }
    }
}```

How about executing two searches, one with 80mi radius and one with 90 mi radius - and then decide which one to display?

Yeah thats the last option . But I think there is gauss like function which take initial distance and offset and keeps on incrementally checking until it finds minimum 1 result . Same is applicable for date as mentioned in my other post for which I still did not get the answer
[https://stackoverflow.com/questions/63028885/elastic-search-is-not-returning-record-for-nearby-input-date/63030752#63030752]

also, you could just search on a wider radius, sort by distance and only retrieve a single result and then check if this result falls into the desired distance?

I think there are a couple of options and you have to pick the one that suits you best.

Please keep in mind, that this is a forum just like stackoverflow does not come with any SLA or guaranteed answers. If you need that, there is commercial support :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.