Search code examples
elasticsearch

Elasticsearch returns total 624 but hits array is empty


I have this query with a strange result: it returns a total of 612 documents but no hits.

This is the query:

{
  "from": 900,
  "size": 30,
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "user_id": "145698489"
              }
            }
          ],
          "should": [
            {
              "bool": {
                "must": [
                  {
                    "range": {
                      "date_created": {
                        "to": "2016-07-30T20:11:09.176-03:00",
                        "gte": "2016-07-07T23:39:45.530-03:00"
                      }
                    }
                  }
                ],
                "must_not": [
                  {
                    "term": {
                      "resource.object.label": "hidden"
                    }
                  }
                ],
                "should": []
              }
            }
          ]
        }
      }
    }
  }
}

And this is the result:

{
    "_shards": {
        "failed": 0,
        "successful": 1,
        "total": 1
    },
    "hits": {
        "hits": [],
        "max_score": 1,
        "total": 612
    },
    "timed_out": false,
    "took": 73
}

But if I change the date ranges I get the results correctly.

Why ES is doing this?


Solution

  • Because you set from to 900. If you have less than 900 hits it won't return hits.