In case somebody would need this in the future, this is how I solved it:
```
{
"query": {
"bool": {
"filter": [
{
"bool": {
"should": [
{
"range": {
"valid_until": {
"gte": "now"
}
}
},
{
"bool": {
"must_not": {
"exists": {
"field": "valid_until"
}
}
}
}
]
}
}
],
"must_not": [],
"should": [],
"must": []
}
}
}
```
Your query is indeed malformed, the filter should be under a `bool` element which should be under the `query` element. Also, when using `or`/`and` you should create separate objects for each filter element (range/term etc..) for example:
{
"size": 50,
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"or": [
{
"term": {
"fromPlace": "liverpool"
}
},
{
"range": {
"query": {
"gte": "01/01/2012",
"lte": "2013",
"format": "dd/MM/yyyy||yyyy"
}
}
}
]
}
}
}
}