Filtered Query in Elastic Search

228 views Asked by At

Filtered Query query not working in elastic search. It gives a error Query Parsing exception with filter malformed, no field after start_object

{
"query": {
  "filtered": {
    "query": {
      "match_all": {}
    },
    "filter": {
      "bool": {
        "must": [],
        "should": [
          {
            "_expires": null
          },
          {
            "_expires": {
              "gte": 1433947304884
            }
          }
        ],
        "must_not": [
          {
            "term": {
              "age": 19
            }
          }
        ]
      }
    }
  }
},
"size": 10,
"from": 0
}

Can somebody help me with this?

1

There are 1 answers

0
Andrei Stefan On BEST ANSWER

Your shoulds should be actually using a filter. For yours you have "_expires": null. This is not a filter.

For example, try:

        {
          "missing": {
            "field": "_expires"
          }
        },
        {
          "range": {
            "_expires": {
              "gte": 1433947304884
            }
          }
        }