# "numHits must be \> 0; please use TotalHitCountCollector if you just need the total hit count" following upgrade to ES 7.7

**URL:** <https://discuss.elastic.co/t/numhits-must-be-0-please-use-totalhitcountcollector-if-you-just-need-the-total-hit-count-following-upgrade-to-es-7-7/233174>\
**Category:** Elasticsearch\
**Created:** [May 18, 2020, 6:17pm UTC](https://discuss.elastic.co/t/numhits-must-be-0-please-use-totalhitcountcollector-if-you-just-need-the-total-hit-count-following-upgrade-to-es-7-7/233174 "2020-05-18T18:17:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![toby\_jn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/toby_jn/32/68567_2.png) [@toby\_jn](https://discuss.elastic.co/u/toby_jn)\
**Post date:** [May 18, 2020, 6:17pm UTC](https://discuss.elastic.co/t/numhits-must-be-0-please-use-totalhitcountcollector-if-you-just-need-the-total-hit-count-following-upgrade-to-es-7-7/233174/1 "2020-05-18T18:17:45Z")

</div>

Following an upgrade from 7.5.1 to 7.7.0 we've started seeing an unusual error with queries used to count the number of documents in an index.

In 7.7.0 this query now returns an error:

```auto
curl -X POST '127.0.0.1:9200/v33.tcpevent-000174/_search?pretty' -H content-type:application/json --data '{"size":0,"sort":[{"@timestamp":{"order":"desc"}},{"conn_uuid":{"order":"desc"}}],"track_total_hits":true}'
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 1,
        "index" : "v33.tcpevent-000174",
        "node" : "j07kSSNmSFueB_E9i911MQ",
        "reason" : {
          "type" : "illegal_argument_exception",
          "reason" : "numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count"
        }
      }
    ],
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count",
      "caused_by" : {
        "type" : "illegal_argument_exception",
        "reason" : "numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count"
      }
    }
  },
  "status" : 400
}

```

In ES 7.5.1 this was fine and didn't cause an error.

I seem to be able to get rid of the error by specifying a non-zero size, or by changing the sort parameter: i.e. both of these searches work:

```auto
{"size":0,"sort":[{"@timestamp":{"order":"desc"}}],"track_total_hits":true}
{"size":1,"sort":[{"@timestamp":{"order":"desc"}},{"conn_uuid":{"order":"desc"}}],"track_total_hits":true}

```

I suspect this is related to index sort as the index is configured with index sort on `{"@timestamp":{"order":"desc"}}`

Changing `track_total_hits` to a specific value gives the same error:

```auto
{"size":0,"sort":[{"@timestamp":{"order":"desc"}},{"conn_uuid":{"order":"desc"}}],"track_total_hits":true} # error

```

It looks to me like this is a bug, though I've tried to reproduce this on a fresh instance with the same mappings and some test data, but it doesn't error in the same way, so will keep looking and try and build a reproducible example.

---

<div class="post-metadata">

**Author:** ![Julie\_Tibshirani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julie_tibshirani/32/55628_2.png) [@Julie\_Tibshirani](https://discuss.elastic.co/u/Julie_Tibshirani)\
**Post date:** [May 18, 2020, 7:05pm UTC](https://discuss.elastic.co/t/numhits-must-be-0-please-use-totalhitcountcollector-if-you-just-need-the-total-hit-count-following-upgrade-to-es-7-7/233174/2 "2020-05-18T19:05:51Z")

</div>

Thanks a lot @toby_jn for raising this, it certainly looks like a bug. It's great that you're working on a consistent reproduction.

In the meantime, would you be able to file a bug report in the [elasticsearch repo](https://github.com/elastic/elasticsearch)? That way we can start to dig into the issue as well. In addition to the search and error, it would help to include the index settings and mappings, plus a sample document.

---

<div class="post-metadata">

**Author:** ![toby\_jn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/toby_jn/32/68567_2.png) [@toby\_jn](https://discuss.elastic.co/u/toby_jn)\
**Post date:** [May 18, 2020, 8:54pm UTC](https://discuss.elastic.co/t/numhits-must-be-0-please-use-totalhitcountcollector-if-you-just-need-the-total-hit-count-following-upgrade-to-es-7-7/233174/4 "2020-05-18T20:54:02Z")

</div>

Issue opened here: [https://github.com/elastic/elasticsearch/issues/56923](https://github.com/elastic/elasticsearch/issues/56923)

---

<div class="post-metadata">

**Author:** ![Julie\_Tibshirani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julie_tibshirani/32/55628_2.png) [@Julie\_Tibshirani](https://discuss.elastic.co/u/Julie_Tibshirani)\
**Post date:** [May 20, 2020, 8:41pm UTC](https://discuss.elastic.co/t/numhits-must-be-0-please-use-totalhitcountcollector-if-you-just-need-the-total-hit-count-following-upgrade-to-es-7-7/233174/5 "2020-05-20T20:41:05Z")

</div>

Thanks @toby_jn, I've moved discussion/ debugging over to that issue.

---

<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:** [June 17, 2020, 8:41pm UTC](https://discuss.elastic.co/t/numhits-must-be-0-please-use-totalhitcountcollector-if-you-just-need-the-total-hit-count-following-upgrade-to-es-7-7/233174/6 "2020-06-17T20:41:08Z")

</div>

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