I want to be able to
- Match a subset of the index with a query_string query.
- Add additional weight to documents that match a set of post-evaluated criterias.
Example:
Let's say I have these two documents:
[
{
"Title": "lord of the rings 1",
"Tags": ["book", "movie", "adventure"]
},
{
"Title": "lord of the rings 2",
"Tags": ["book", "adventure"]
}
]
I make a search with this query:
{
"query": {
"function_score": {
"query": {
"query_string": {
"fields": [
"Title"
],
"query": "lord of the rings adventure movie"
}
},
"functions": [
{
"filter": {
"match": {
"Tags": {
"query": "lord of the rings adventure movie"
}
}
},
"weight": 2.0
}
]
}
}
}
The specific mappings/settings should not be relevant to this question, so I skipped them.
Question:
How do I make the match query inside the functionscore filter pay attention to how well the match query matches the query instead of just a boolean decision whether to apply the static weight or not? In this case, the first document is a better match, since it matches both tags (adveture, movie), whereas the second document only matches one of the tags (adventure), but they come out being equal matches because of the boolean nature of functionscore filters.
I can't move the match into the root query, as I don't want to include other documents with those tags in the output, but I still want the most closely matched document to come first.
Maybe there is a completely different approach to this issue that I'm just not aware of.
Any help is appreciated.