With Elasticsearch function score query with decay against a geo-point, is it possible to set a target distance? -


it doesn't seem possible based on https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html , i'd confirmation.

in plain english, i'm asking score results (with geo-point locations) how close 500km latitude, longitude origin.

it's confusing because there parameter called "offset" according documentation doesn't seem offset origin (eg. distance) instead seems mean "threshold" instead.

i see few ways accomplish this:

a. 1 way sort distance in reverse order origin. you'd use geo_distance query , sort distance. in following query, distant documents come first, i.e. sort value distance origin , we're sorting in decreasing order.

{   "query": {     "filtered": {       "filter": {         "geo_distance": {           "from" : "100km",           "to" : "200km",           "location": {             "lat": 10,             "lon": 20           }         }       }     }   },   "sort": [     {       "_geo_distance": {         "location": {           "lat": 10,           "lon": 20         },         "order": "desc",         "unit": "km",         "distance_type": "plane"       }     }   ] } 

b. second way involves using geo_distance_range query in order define "ring" around origin. width of ring somehow symbolize offset + scale you'd use in gauss function (although there no decay). here define ring 10km wide @ 500km distance origin point , sort documents distance in ring.

{   "query": {     "filtered": {       "filter": {         "geo_distance_range": {           "from": "495km",           "to": "505km",           "location": {             "lat": 10,             "lon": 20           }         }       }     }   },   "sort": [     {       "_geo_distance": {         "location": {           "lat": 10,           "lon": 20         },         "order": "desc",         "unit": "km",         "distance_type": "plane"       }     }   ] } 

c. last way bit more involved. we're after "inverse gauss" shape, this figure (33), upside-down, or this one better represents donut shape we're after. can combine solution b above gauss function score within ring. in query below, we're saying we're interested in locations around 500km origin , let gauss function kick in documents. it's not perfect, though, might close enough need.

{   "query": {     "filtered": {       "filter": {         "geo_distance_range": {           "from": "495km",           "to": "505km",           "location": {             "lat": 10,             "lon": 20           }         }       },       "query": {         "function_score": {           "functions": [             {               "gauss": {                 "location": {                   "origin": {                     "lat": 10,                     "lon": 20                   },                   "offset": "500km",                   "scale": "5km"                 }               }             }           ]         }       }     }   },   "sort": {     "_score": "desc"   } }   

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -