Hey everyone,
I need help with query syntax!
I'm trying to build a compound bool query that filters out documents that do not match a certain criteria, essentially a double negative.
I want to return relevant events for our users, and an attribute of these events is to be either public or private ("private" = true). I want to return public events AND return private events that the user is either attending OR invited to. Stated inversely, I want to return events that are NOT private AND do NOT have the user either attending OR invited. There are also a few other attributes to filter out as you'll see in the example below, such as events where we set "isHidden" = true or "isCanceled" = true.
I have tried various structures, but the closest I can come up with is the following:
{
"query": {
"bool": {
"must_not": [
{
"term": {
"isHidden": true
}
},
{
"term": {
"isCanceled": true
}
},
{
"bool": {
"must": [
{
"term": {
"private": true
}
}
],
"must_not": [
{
"term": {
"invited": "userId1"
}
},
{
"term": {
"attenders": "userId1"
}
}
]
}
}
]
}
}
}
However when I execute this query, it always filters out private events, even ones where the userId1 is included in "invited" field, for example.
How can I properly query this case?
Thank you!