# Count Occurrence Of Value

**URL:** <https://discuss.elastic.co/t/count-occurrence-of-value/184551>\
**Category:** Elasticsearch\
**Created:** [June 6, 2019, 10:12am UTC](https://discuss.elastic.co/t/count-occurrence-of-value/184551 "2019-06-06T10:12:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkelsen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkelsen/32/46291_2.png) [@dkelsen](https://discuss.elastic.co/u/dkelsen)\
**Post date:** [June 6, 2019, 10:12am UTC](https://discuss.elastic.co/t/count-occurrence-of-value/184551/1 "2019-06-06T10:12:23Z")

</div>

Hi,

I'm trying to figure out how to get the total number of occurrences of a certain value in an index.  
I've tried using Value Count Aggregation, but that doesn't seem to work.

```
"_source" : {
          "category" : [
            "Men's Clothing"
          ],
          "currency" : "EUR",
          "customer_first_name" : "Eddie",
          "customer_full_name" : "Eddie Underwood"
}

```

Let's say I wanted to see how many times the value "Eddie" occurs, how would I do that?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 7, 2019, 12:44pm UTC](https://discuss.elastic.co/t/count-occurrence-of-value/184551/2 "2019-06-07T12:44:06Z")

</div>

It depends on how you are counting. Does the above document count twice or do you only want to count on the first name field?

---

<div class="post-metadata">

**Author:** ![dkelsen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkelsen/32/46291_2.png) [@dkelsen](https://discuss.elastic.co/u/dkelsen)\
**Post date:** [June 7, 2019, 1:19pm UTC](https://discuss.elastic.co/t/count-occurrence-of-value/184551/3 "2019-06-07T13:19:12Z")

</div>

I want to count the occurrence of that value for a specific field in all my documents, so in this case how many "Eddie" in "customer\_first\_name".

I've found out that I can get a count value by doing

```
"query": {
	"term": {
		"customer_first_name.keyword": { 
			"value": "Eddie" 
		}
	}
}
```

---

<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:** [July 5, 2019, 1:19pm UTC](https://discuss.elastic.co/t/count-occurrence-of-value/184551/4 "2019-07-05T13:19:13Z")

</div>

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