# Can't we get total number of matches in \_search api?

**URL:** https://discuss.elastic.co/t/cant-we-get-total-number-of-matches-in-search-api/271612
**Category:** Elasticsearch
**Created:** [April 29, 2021, 9:52am UTC](https://discuss.elastic.co/t/cant-we-get-total-number-of-matches-in-search-api/271612 "2021-04-29T09:52:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![raja\_augstin](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@raja\_augstin](https://discuss.elastic.co/u/raja_augstin)
#### Post date: [April 29, 2021, 9:52am UTC](https://discuss.elastic.co/t/cant-we-get-total-number-of-matches-in-search-api/271612/1 "2021-04-29T09:52:44Z")

</div>

can't we get total number of matches in \_search api?

i'm using following search api to get total matched document and to find number of match for the given query.  
in this we don't receive the actual total match for the given query rather then results saying total value 10000 and relation : gte.

i'm not sure how to get the total number of match that i used to receive older versions of elasticsearch ex:5.6.3 v.

[https://host:9202/index/\_search](https://host:9202/index/_search)

Response from 7.11.2  
"hits": {  
"total": {  
**"value": 10000,**  
"relation": "gte"  
}

Response from 5.6.3

```
"hits": {
    "total": 1366000,
    "max_score": 1.0,
    .....
  }
```

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [April 29, 2021, 10:35am UTC](https://discuss.elastic.co/t/cant-we-get-total-number-of-matches-in-search-api/271612/2 "2021-04-29T10:35:43Z")

</div>

Take a look at [Search your data | Elasticsearch Guide [7.12] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.12/search-your-data.html#track-total-hits)

Why do you need the total number of hits?

---

<div class="post-metadata">

### Author: ![raja\_augstin](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@raja\_augstin](https://discuss.elastic.co/u/raja_augstin)
#### Post date: [April 29, 2021, 11:09am UTC](https://discuss.elastic.co/t/cant-we-get-total-number-of-matches-in-search-api/271612/3 "2021-04-29T11:09:15Z")

</div>

@warkolm , Thanks for sharing the document.

total # of hits is required to show for the user saying this many records matched for ur search, and out of this we are showing n docs.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [April 29, 2021, 11:29am UTC](https://discuss.elastic.co/t/cant-we-get-total-number-of-matches-in-search-api/271612/4 "2021-04-29T11:29:48Z")

</div>

There are some optimisations so the response will be faster if you don't track the total number of hits after 10000 hits.

One good practice IMO is to say to the user:

- When you have hits below 10000:

> Your query is matching 5678 documents. Here are the 10 first documents.

- When you have more than 10000 hits:

> Your query is matching more than 10.000 documents. Here are the 10 first documents.

My 2 cents.

---

<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: [May 27, 2021, 11:30am UTC](https://discuss.elastic.co/t/cant-we-get-total-number-of-matches-in-search-api/271612/5 "2021-05-27T11:30:44Z")

</div>

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