I'm using Elastic Search, with query match_all and filtering. In my situation I want to apply a general filter and filters by condition.
Here in pseudo:
- query: match all (works fine)
- filter range date between d1 and d2 (works fine without bullet 3)
- filter (apply only if field exists, but how?)
- etc.
See the following code. I want only apply the "groups" filter if the "groups" field exists! The "exists" filter doesn't take effect in that case.
"query":
{
"filtered":
{
"query":
{
"match_all": {}
},
"filter":
{
"bool":
{
"must":
{
"range":
{
"date": {
"from": "2015-06-01",
"to": "2015-06-30"
}
}
},
"must_not":
{
"term":
{
"e.state": 0
}
}
}
},
"filter":
{
"bool":
{
"must":
{
"exists": {"field": "groups"},
"filter":
{
"bool":
{
"must":
{
"term": {"groups.sex": "w"}
},
"should":
{
"terms": {"groups.categories.id": [7,10]}
}
}
}
}
}
}
}
}
}