How to favor adjacent words match, but to allow partial match too

I'm writing the text search app for some internal tool, so looking for some simple solution which doesn't require index-time changes (so not looking at N-gram indexing yet).

Let's say we have two documents with titles of same length

  • "Good document about everything around"
  • "Not Good but bad document"

Search phrase is "very good document".

Goal is to return both documents (i.e. allow partial match, as they don't have "very"), but also to boost "Good document about everything around" higher because "good document" are adjacent there.

In order to support boost by adjacent words match, it is usually recommended to use match_phrase with slop. But it doesn't work in my case, because it doesn't allow partial match (doesn't allow to omit "very").

Why don't you create a boolean query, with clauses for match_phrase with slop and another match clause that would hit on your partial matches? You can experiment with minimum_should_match and if scoring is an issue you can also wrap it in a dis_max query.

Do you mean I need to have should with match_phrase for all possible sub-strings of my initial query?

When query is relatively short ( "very good document "), then there will be only 3 sub-strings:

  • "very good"
  • "good document"
  • "very good document"

But as a query gets longer, the number of sub-strings will grow fast.
If this is the only option, I will try.