I have an ElasticSearch index with a list of "shops".
I'd like to allow customers to search these shops by both geo_distance
(so, search for a point and get shops near that location), and textual match, like matches on shop name / address.
I'd like to get results that match either of these two criteria, and I'd like the order of these results to be a combination of both. The stronger the textual match, and the closer to the point searched, the higher the result. (Obviously, there's going to be a formula to combine these two, that'll need tweaking, not too worried about that part yet).
My issue / what I've tried:
geo_distance
is afilter
, not aquery
, so I can't combine both on thequery
part of the request.I can use a
bool => should
filter (rather than query) that matches on either name or location. This gives me the results I want, but not in order.I can also have
_geo_distance
as part of asort
clause so that documents closer to the point rank higher.
What I haven't figured out is how I would take the "regular" _score
that ElasticSearch gives to documents when doing textual matches, and combine that with the geo_distance
score.
By having the textual match in the filter, it doesn't seem to affect the score of documents (which makes sense). And I don't see how I could combine the textual match in the query
part and a geo_distance filter
so it's an OR
rather than an AND
.
I guess my best bet would be the equivalent of this:
{
function_score: {
query: { ... },
functions: [
{ geo_distance function },
{ multi_match_result score },
],
score_mode: 'multiply'
}
}
but I'm not sure you can do geo_distance
as a score function, and I don't know how to have multi_match_result score
as a score function, or if it's even possible.
Any pointers will be greatly appreciated.
I'm working with ElasticSearch v1.4, but I can upgrade if necessary.