Closed beseven closed 7 years ago
In ES there is the concept of queries and filters. The distance is a filter as I believe it is used to exclude locations based on a rough but computationally effective calculation and only then calculates distance on the remainder. This means it doesn't have to do a computationally intensive distance calculation on the whole index.
The distance we use can be set to something much larger than that which any user would travel and then return the top n ordered by distance.
A quick play with the API via curl showed that extending the distance to 50 miles and adding a size
property to the query had the desired result.
Example
{
"size": 3,
"query": {
"bool": {
"must" : {
"match_all" : {}
},
"filter": {
"geo_distance": {
"distance": "50mi",
"location.coordinates": {
"lon": -1.46519099452929,
"lat": 54.0095586395326
}
}
}
}
},
"sort": [
{
"_geo_distance": {
"location.coordinates": {
"lon": -1.46519099452929,
"lat": 54.0095586395326
},
"order": "asc",
"unit": "mi",
"distance_type": "plane"
}
}
]
}
That lat/long above previously returned 0 results.
@neilbmclaughlin Do you want me to add this in #144 ?
Resolved by extending radius to 50 miles.
As part of the postcode validation, it was raised that YO62 4LA is 3.6 mi away from the nearest GP but the current radius is of 5km. A couple of solutions:
increase to 20mi similar to https://github.com/nhsuk/connecting-to-services (needs user needs basis for the number)
refactor to not depend on the distance but bring back the nearest 30 docs (needs user needs basis for the number
both will require work on the https://github.com/nhsuk/profiles-db-elastic side too.