Background:
We have requirement for following:
- Data matching keyword should be returned.
- Data has longitude and latitude fields, result should be near specified lat long.
- Returned result should contain distance field, which specified distance between given lat long and lat long contained in data.
- Data should be sorted accouding to MultiMatch score.
Reading the tutorial in this link Spatial Search ElasticSearch tutorial I have constructed following query in C#.
var res = await _elasticClient
.SearchAsync<Results>(
s =>
s.Type("Data")
.Skip(skip)
.Take(limit)
.SortGeoDistance(es =>
es.Ascending().OnField("Coordinates").Unit(GeoUnit.Kilometers).PinTo(lat,lng))
.Query(
q1 =>
q1.Filtered(
f1 =>
f1.Query(q2 => q2.MultiMatch(mm => mm.OnFields(MultiMatchFieldsArray)
.Query(keyword)
.Type(TextQueryType.MostFields)))
.Filter(f2 => f2.GeoDistance("Coordinates",gf => gf.Distance(10,GeoUnit.Kilometers)
.Location(lat,lng))))));
According to tutorial I have to use SortGeoDistance method to get distance in result. Using SortGeoDistance will sort result according to distance, but in need result to be sorted according to MultiMatch score.