scala - elastic4s geodistance sort query syntax -


i using elastic4s version 1.6.2 , need write query searches given geo location, sorts results distance , returns distance. can using request in curl struggling find correct syntax , example got geolocation sort.

case class store(id: int, name: string, number: int, building: option[string] =     none, street: string, postcode: string,county: string, geolocation: geolocation)  case class geolocation(lat: double, lon: double)   val createmappings = client.execute { create index "stores" mappings (   "store" as(     "store" typed stringtype,     "geolocation" typed geopointtype     )   ) }  def searchbygeolocation(geolocation: geolocation) = { client.execute {   search in "stores" -> "store" postfilter {     geodistance("geolocation") point(geolocation.lat, geolocation.lon) distance(2, kilometers)   }   } } 

does knows how add sort distance geo location , distance following curl command works expected

curl -xget 'http://localhost:9200/stores/store/_search?pretty=true' -d ' { "sort" : [   {       "_geo_distance" : {           "geolocation" : {                 "lat" : 52.0333793839746,                 "lon" : -0.768937531935448           },            "order" : "asc",           "unit" : "km"       }   } ], "query": { "filtered" : {     "query" : {         "match_all" : {}     },     "filter" : {         "geo_distance" : {             "distance" : "20km",             "geolocation" : {                 "lat" : 52.0333793839746,                 "lon" : -0.768937531935448             }         }     } } 

} }'

not expert in elasti4s query should equivalent curl command:

val geolocation = geolocation(52.0333793839746, -0.768937531935448) search in "stores" -> "store" query {     filteredquery filter {       geodistance("geolocation") point(geolocation.lat, geolocation.lon) distance(20, kilometers)     }   } sort {     geosort("geolocation") point (geolocation.lat, geolocation.lon) order sortorder.asc   } 

it prints following query:

{   "query" : {     "filtered" : {       "query" : {         "match_all" : { }       },       "filter" : {         "geo_distance" : {           "geolocation" : [ -0.768937531935448, 52.0333793839746 ],           "distance" : "20.0km"         }       }     }   },   "sort" : [ {     "_geo_distance" : {       "geolocation" : [ {         "lat" : 52.0333793839746,         "lon" : -0.768937531935448       } ]     }   } ] } 

asc default value of sorting can remove order sortorder.asc. wanted explicit in example.


Comments