When using a match query, is it possible to search only when there are a certain number of terms in the query?
I need that functionality, not for the entire query, but as part of a subquery that I will put inside a boolean query.
For example, is it possible to create a query so that it only returns results if there are at least 3 terms in the query?
With the standard analyzer, I shouldn't get any results for the query below(because the query contains only two terms).
"query": {
"match": {
"content": {
"query": "dog cat"
}
}
}
I should get search results for the queries below. (since there are 4 terms in the query, I'm assuming there are matching documents)
"query": {
"match": {
"content": {
"query": "dog cat puppy kitty"
}
}
}
Is there any way to determine if a match is made by the number of terms contained in the query as shown above?
It's undocumented, but I was able to write a similar query using the "or" operator and minimum_should_match.
"query": {
"match": {
"content": {
"query": "term1 term2 term3",
"operator": "or",
"minimum_should_match": 3
}
}
}
However, it's not perfect, and won't work in the following cases
"query": {
"match": {
"content": {
"query": "term1",
"operator": "or",
"minimum_should_match": 3
}
}
}
In the above case, since there is only 1 term, it appears that minimum_should_match does not apply.
I was wondering if there is any other way to determine whether to match by the number of terms in the query.
The ES version used is 7.15.2.