How to properly write boolean or logic in elasticsearch?
The main reason you're having trouble getting results is because you're trying to do a term
filter on actionType
, which is an analyzed field. If you want to do term
matching on that field, you'll need to update your type mapping to set that field to not_analyzed
. See this example mapping:
{ "record": { "properties": { "actionType": { "type": "string", "index": "not_analyzed", }, "loId": { "type": "long" }, "paId": { "type": "long" }, "prId": { "type": "long" }, "timestamp": { "type": "long" }, "uid": { "type": "long" }, "vId": { "type": "long" } } }}
Read up on mappings starting here: http://www.elasticsearch.org/guide/reference/mapping/. You'll need to reindex your data. With that fixed, here's a query that will work:
{ "query": { "filtered": { "query": {"match_all":{}}, "filter": { "bool": { "must": [ {"term": {"loId":6}}, { "or": [ {"term":{"actionType": "SAVE_DATA"}}, {"term":{"actionType": "OPEN_SCREEN"}} ] } ] } } } }}