Hello community!
I'm encountering an issue with sorting by geodistance in Elasticsearch and could use some guidance. I have set up an index with a nested geo_location
field, and my intention is to sort the search results based on geodistance from a specified point.
However, despite my efforts, the sorting seems to have no effect on the results. And the result is relevent to the searchterm, distance and geopoint specified in the query. I've double-checked my implementation, but I'm still unable to achieve the desired sorting behavior.
If anyone has experience with sorting by geodistance in Elasticsearch, particularly with nested geo_location fields, I would greatly appreciate any insights or suggestions you can offer. Your help would be invaluable in resolving this issue.
Thank you in advance for your assistance!
current mapping: :
{
"indexemployee": {
"mappings": {
"properties": {
"properties": {
"properties": {
"profession": {
"properties": {
"code": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"label": {
"type": "text",
"analyzer": "autocomplete"
}
}
}
}
},
"otherData": {
"properties": {
"workplace": {
"type": "nested",
"properties": {
"ent_geo": {
"type": "nested",
"properties": {
"properties": {
"properties": {
"address": {
"properties": {
"countryCode": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"countryName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"geolocation": {
"type": "geo_point"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
search query :
{
"sort": [
{
"_geo_distance": {
"otherData.workplace.ent_geo.properties.address.geolocation": {
"lat": "41.12",
"lon": "-71.34"
},
"order": "desc",
"unit": "km",
"mode": "min",
"nested": {
"path": "otherData.workplace"
}
}
}
],
"query": {
"bool": {
"must": [
{
"match": {
"properties.profession.label": "Doctor"
}
},
{
"nested": {
"path": "otherData.workplace",
"query": {
"nested": {
"path": "otherData.workplace.ent_geo",
"query": {
"bool": {
"must": [
{
"geo_distance": {
"distance": "30km",
"otherData.workplace.ent_geo.properties.adresse.geolocation": {
"lat": "41.12",
"lon": "-71.34"
}
}
}
]
}
}
}
}
}
}
]
}
}
}