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!