I have created an index which has nested locations of Geo point type.
When sorting the results are only returning one distance. How to get distance of all locations with in a single document.
Please help me with this issue.
Query
dealers/_search/
{
"sort": [
{
"_geo_distance": {
"locations.point": {
"lat": 50.69,
"lon": -3.51
},
"nested_path": "locations",
"order": "asc",
"unit": "km"
}
}
],
"query": {
"nested": {
"path": "locations",
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "200km",
"locations.point": {
"lat": 50.69,
"lon": -3.51
}
}
}
}
}
}
}
}
Index definition
/dealers/
{
"mappings": {
"_doc": {
"properties": {
"id": {
"type": "integer"
},
"locations": {
"type": "nested",
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"point": {
"type": "geo_point"
}
}
}
}
}
}
}
Sample Documents
/dealers/_doc/1
{
"locations": [
{
"name": "Exeter",
"point": {
"lat": 50.69,
"lon": -3.51
}
},
{
"name": "Swindon",
"point": {
"lat": 51.54,
"lon": -1.85
}
},
{
"name": "Reading",
"point": {
"lat": 51.42,
"lon": -0.97
}
}
]
}
Second Sample document
/dealers/_doc/2
{
"locations": [
{
"name": "Cobham",
"point": {
"lat": 51.33,
"lon": -0.41
}
},
{
"name": "Swindon",
"point": {
"lat": 51.54,
"lon": -1.85
}
},
{
"name": "Coventry",
"point": {
"lat": 52.43,
"lon": -1.49
}
}
]
}
Third Document sample
/dealers/_doc/3
{
"locations": [
{
"name": "Durham",
"point": {
"lat": 54.78,
"lon": -1.54
}
},
{
"name": "Swindon",
"point": {
"lat": 51.54,
"lon": -1.85
}
},
{
"name": "Coventry",
"point": {
"lat": 52.43,
"lon": -1.49
}
}
]
}
Thank you,
Krishna