# Bitwise logical operation in filter

I see this get asked many times over the years. Is there a way to do bitwise operation in query filtering? For instance, I may have a data field for store opening day: M,T,W,Th,F,S,Sun. So:
1111100: store opens on weekdays, not weekends
1111111: opens everyday
1010000: opens monday and wednesday only.
That way I could use this for filtering to get stores that are open today.

Please point me to right documents if there's such way. Thanks.

{
"opening_days": ["M","T","W","Th","F","S","Sun"]
}
{
"opening_days": ["M","T","W","Th","F"]
}
{
"opening_days": ["M","W"]
}

opening_days:S

Thanks Mikhail.
I realize that the example is not exactly what I'm looking for. Let me try it this way: let's say each document has 0 to 5 locks:
00000 -- no lock, anyone can access this document.
10000 -- user with key 1 can access this document.
10010 -- user with keys 1 and 4 to access this document.

In search query, I'd like to use the user's keys to filter search results: user with key "10000" can access 1st and 2nd documents. User with "01111" can only access 1st document.

In real world problem, I may need to define 200 locks for all documents. What I'm looking for is long bitwise operation in Elastic.

Thanks for reading it.

Ok. I've got it.

User with "01111" can only access 1st document

It's the key requirement. In boolean logic it hits the second doc 10010 ,
but this doc requires to be hit twice to appear in results.
This problem is known like boolean expression search or sometimes reverse
search. eg percolator does something similar.

I've done it on other search engine based on Lucene, you know. It worked as
follows:
we issue boolean query like keys:(2 OR 3 OR 4 ..)
but then we need to score every term hit as 1, sum them and cut off docs
having score less then number of tokens in keys fields.
It's a little bit cumbersome, but feasible. Probably Elastic already has
something more convenient.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.