Suppose that my index have two documents:
- "foo bar"
- "bar foo"
When I do a regular match query for "bar foo", both documents match correctly but they get equal relevance scores. However, I want the order of words to be significant during scoring. In other words, I want "bar foo" to have a higher score.
So I tried putting my match query inside the must clause of a bool query and included a match_phrase (with the same query string) as the should clause. This seems to score hits correctly, until I do a search with "bar test foo". In that case match_phrase query doesn't seem to match, and the hits are returned with equal scores again.
How can I construct my index/query so that it takes word order into account but does not require all searched words to exist in document?