I have an index of documents. I want to filter for documents that are either public, or that are shared to the group by members of my group (users 1 and 3).
privacy = "public" OR (privacy = "group" AND user_id in (1,3))
I can do them separately, but how do I combine them with OR?
"filter" : [
{"terms" : { "privacy" : ["public"]}},
]
"filter" : [
{"terms" : { "privacy" : ["group"]}},
{"terms" : { "user_id" : [1,3]}},
]
Documents:
- {"id":1,"user_id":1, "privacy":"public","title":"Cooking for One",}
- {"id":3,"user_id":1, "privacy":"group","title":"Three's Company"}
- {"id":4,"user_id":2, "privacy":"public","title":"Four Ways to Diet"}
- {"id":6,"user_id":2, "privacy":"group","title":"Six O'Clock News"}
- {"id":7,"user_id":3, "privacy":"public","title":"Lucky Seven"}
- {"id":9,"user_id":3, "privacy":"group","title":"Nine Animals to Draw"}
The right query will return documents 1,3,4,7,9, but not 6.