php - similar sphinxsearch geodistance sorting in elasticsearch -


i have done aggregation name geo-distance sorting not working properly. have achieved aggregation , distance calculation. don't know how soring bucket distance value. kindly suggest me how achieved?

mapping:-

put /museums {     "mappings": {         "doc": {             "properties": {                 "location": {                     "type": "geo_point"                 }             }         }     } } 

data values:

post /museums/doc/_bulk?refresh {"index":{"_id":1}} {"location": "52.374081,4.912350", "name": "nemo science museum"} {"index":{"_id":2}} {"location": "52.369219,4.901618", "name": "museum het rembrandthuis"} {"index":{"_id":3}} {"location": "52.371667,4.914722", "name": "nederlands scheepvaartmuseum"} {"index":{"_id":4}} {"location": "51.222900,4.405200", "name": "letterenhuis"} {"index":{"_id":5}} {"location": "48.861111,2.336389", "name": "musée du louvre"} {"index":{"_id":6}} {"location": "48.860000,2.327000", "name": "musée d'orsay"} {"index":{"_id":7}} {"location": "52.374081,4.912350", "name": "nemo science museum"} {"index":{"_id":8}} {"location": "48.861111,2.336389", "name": "musée du louvre"} 

elastic search query:

post /museums/_search?size=0 {         "query": {          },         "sort": {             "_geo_distance": {                 "location": {                         "lat": 52.3760,                         "lon": 4.894                 },                 "order": "asc",                 "unit": "km",                 "distance_type": "arc"             }         },         "aggregations": {             "by_id": {                 "terms": {                     "field": "name.keyword",                     "order": {                       "_count": "asc"                     },                     "size": 20                 },                 "aggregations":{                   "top":{                     "top_hits":                     {                       "sort":{                         "_geo_distance":{ "location":{"lat":19.143172,"lon":72.824966                           }               }     } } } } } } } 

above query giving result not sorting distance.

i may have misread you, trying fetch locations within x km/miles point?

if so, there equation called haversine formula, uses spherical trigonometry calculate areas within distance! looks this:

r = earth’s radius (mean radius = 6,371km) Δlat = lat2− lat1 Δlong = long2− long1 = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2) c = 2.atan2(√a, √(1−a)) d = r.c angles need in radians pass trigonometric functions 

which mathematical me. in mysql query however, looks this:

select *,   ( 3959 * acos( cos( radians(55.864237) ) * cos( radians( latitude ) )   * cos( radians( longitude ) - radians(-4.251806) ) + sin( radians(55.864237) )   * sin( radians( latitude ) ) ) ) distance  postcodes having distance < 20  order distance limit 1; 

here check area within 20 miles, can make short or long want. 3959 figure @ start of query number used miles, if using kilometres should change number 6371. have limited 1 row, want closest match, may want change in other situations!


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -