# Total count of a field

**URL:** <https://discuss.elastic.co/t/total-count-of-a-field/339289>\
**Category:** Elasticsearch\
**Created:** [July 26, 2023, 9:58am UTC](https://discuss.elastic.co/t/total-count-of-a-field/339289 "2023-07-26T09:58:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dana\_Pavaday](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dana_pavaday/32/123188_2.png) [@Dana\_Pavaday](https://discuss.elastic.co/u/Dana_Pavaday)\
**Post date:** [July 26, 2023, 9:58am UTC](https://discuss.elastic.co/t/total-count-of-a-field/339289/1 "2023-07-26T09:58:29Z")

</div>

Hello everyone,

I need to get the total count of a field in Elasticsearch (in my case, the number of clients in client field). How do I write the query in Dev tools?

---

<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:** [July 26, 2023, 11:35am UTC](https://discuss.elastic.co/t/total-count-of-a-field/339289/2 "2023-07-26T11:35:50Z")

</div>

A [terms aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html) should do it I guess...

---

<div class="post-metadata">

**Author:** ![Dana\_Pavaday](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dana_pavaday/32/123188_2.png) [@Dana\_Pavaday](https://discuss.elastic.co/u/Dana_Pavaday)\
**Post date:** [July 26, 2023, 3:35pm UTC](https://discuss.elastic.co/t/total-count-of-a-field/339289/3 "2023-07-26T15:35:43Z")

</div>

Hello @dadoonet,

I tried the terms aggregation query but it is not providing the total count of client. It is dividing the client into different parts and then providing the total of each part.

---

<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:** [July 26, 2023, 3:50pm UTC](https://discuss.elastic.co/t/total-count-of-a-field/339289/4 "2023-07-26T15:50:12Z")

</div>

What do you mean?

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can **copy and paste in Kibana dev console** , click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Have a look at the [Elastic Stack and Solutions Help · Forums and Slack | Elastic](https://elastic.co/community/help) page. It contains also lot of useful information on how to ask for help.

---

<div class="post-metadata">

**Author:** ![Dana\_Pavaday](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dana_pavaday/32/123188_2.png) [@Dana\_Pavaday](https://discuss.elastic.co/u/Dana_Pavaday)\
**Post date:** [July 27, 2023, 7:34am UTC](https://discuss.elastic.co/t/total-count-of-a-field/339289/5 "2023-07-27T07:34:16Z")

</div>

Hello @dadoonet,

Please see the 2 attached screenshots.

 ![Client](https://us1.discourse-cdn.com/elastic/original/3X/2/5/257dc371b9c7fd46ef1ebd91ad56299f96bda398.png)

 ![total count](https://us1.discourse-cdn.com/elastic/original/3X/c/d/cd6051b0141377664c595e1b1068687bb3448e60.png)

In the first screenshot, we can see that the client field is being divided into small parts. And I need the total count of client to be displayed like in the second screenshot.

---

<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:** [July 27, 2023, 9:36am UTC](https://discuss.elastic.co/t/total-count-of-a-field/339289/6 "2023-07-27T09:36:56Z")

</div>

Please don't post images of text as they are hard to read, may not display correctly for everyone, and are not searchable.

Instead, paste the text and format it with `</>` icon or pairs of triple backticks (```), and check the preview window to make sure it's properly formatted before posting it. This makes it more likely that your question will receive a useful answer.

But anyway, here I think you want to use: [Cardinality aggregation | Elasticsearch Guide [8.9] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html)

---

<div class="post-metadata">

**Author:** ![Dana\_Pavaday](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dana_pavaday/32/123188_2.png) [@Dana\_Pavaday](https://discuss.elastic.co/u/Dana_Pavaday)\
**Post date:** [July 28, 2023, 7:04am UTC](https://discuss.elastic.co/t/total-count-of-a-field/339289/7 "2023-07-28T07:04:43Z")

</div>

Hello @dadoonet,

Well noted. And thank you for your help.

---

<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:** [August 25, 2023, 7:05am UTC](https://discuss.elastic.co/t/total-count-of-a-field/339289/8 "2023-08-25T07:05:07Z")

</div>

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