Match query with specific order of terms

We need to match a set of terms in a field while taking the order into account.

Example:
The document:

{
  "my_field": "foo bar"
}

It should match when the user search for
foo bar, foo bar baz or baz foo bar
but not if the terms are in a different order
bar foo, bar foo baz or baz bar foo

Using the match query with a minimum_should_match yields better results than without, but the wrong order of terms is matching too.

POST _search
{
  "query": {
    "match": {
      "my_field": {
        "query":"foo bar baz",
        "minimum_should_match": "2"
      }
    }
  }
}

Using the match_phrase query is not working, as the users input contain more/other terms too.

POST _search
{
  "query": {
    "match_phrase": {
      "my_field": "foo bar baz"
    }
  }
}

Any Ideas?

Cheers!

Hi @Rafael_Kubina

I dont know if help you but there is the Interval Query.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.