# Total hits count not equal to doc\_count total

**URL:** <https://discuss.elastic.co/t/total-hits-count-not-equal-to-doc-count-total/264863>\
**Category:** Elasticsearch\
**Created:** [February 19, 2021, 1:29pm UTC](https://discuss.elastic.co/t/total-hits-count-not-equal-to-doc-count-total/264863 "2021-02-19T13:29:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rivariv](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@rivariv](https://discuss.elastic.co/u/rivariv)\
**Post date:** [February 19, 2021, 1:29pm UTC](https://discuss.elastic.co/t/total-hits-count-not-equal-to-doc-count-total/264863/1 "2021-02-19T13:29:54Z")

</div>

Hi!  
I am using bucket aggregation- terms. Something is going wrong and I cannot seem to solve it. Spent a lot of time already.  
The total keys I have in my bucket and their doc\_count sum is not coming to be equal total hits.  
Below is my request:

```auto
    {
      "aggs": {
        "2": {
          "terms": {
            "field": "client.keyword",
            "order": {
              "_count": "desc"
            },
            "size": 1000
          }
        }
      },
      "size": 0,
      "_source": {
        "excludes": []
      },
      "stored_fields": [
        "*"
      ],
      "script_fields": {},
      "docvalue_fields": [
        {
          "field": "@timestamp",
          "format": "date_time"
        },
        {
          "field": "timestamp",
          "format": "date_time"
        }
      ],
      "query": {
        "bool": {
          "must": [
            {
              "match_all": {}
            }
          ],
          "filter": [
            {
              "match_phrase": {
                "login_status.keyword": {
                  "query": "REJECT"
                }
              }
            },
            {
              "range": {
                "@timestamp": {
                  "format": "strict_date_optional_time",
                  "gte": "2021-02-19T13:16:29.323Z",
                  "lte": "2021-02-19T13:26:29.323Z"
                }
              }
            }
          ],
          "should": [],
          "must_not": []
        }
      }
    }

```

and this is the response I am receiving:

```auto
    {
      "took": 685,
      "timed_out": false,
      "_shards": {
        "total": 8,
        "successful": 8,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": 41,
        "max_score": null,
        "hits": []
      },
      "aggregations": {
        "2": {
          "doc_count_error_upper_bound": 0,
          "sum_other_doc_count": 0,
          "buckets": [
            {
              "key": "a:v:c:20:e3:a8",
              "doc_count": 5
            },
            {
              "key": "x:y:89:c7:07:9a",
              "doc_count": 1
            }
          ]
        }
      }
    }

```

What am I doing wrong here?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 19, 2021, 1:30pm UTC](https://discuss.elastic.co/t/total-hits-count-not-equal-to-doc-count-total/264863/2 "2021-03-19T13:30:34Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
