Maybe Operator
In addition to the basic logical operators, there is an additional logical
operator _and_maybe
which matches any document which matches A (whether or
not B matches). If only B matches, then _and_maybe
doesn’t match. For this
operator, the weight is the sum of the matching subqueries, so:
_and_maybe
- Finds any document which matches the first element of the array and whether or not matches the rest.
- Documents which match A and B match with the weight of A+B
- Documents which match A only match with weight of A
This allows you to state that you require some terms (A) and that other terms (B) are useful but not required.
Example
For example, the following matches all of those who like bananas and which maybe are also are brown-eyed females. It will return brown-eyed females who like bananas first:
SEARCH /bank/
{
"_query": {
"_and_maybe": [
{
"favoriteFruit": "banana"
},
{
"_and": [
{ "gender": "female" },
{ "eyeColor": "brown" }
]
}
]
}
}