# In elasticsearch , Is there a way to count the number of values in the same field separately?

**URL:** <https://discuss.elastic.co/t/in-elasticsearch-is-there-a-way-to-count-the-number-of-values-in-the-same-field-separately/206721>\
**Category:** Kibana\
**Created:** [November 6, 2019, 4:45am UTC](https://discuss.elastic.co/t/in-elasticsearch-is-there-a-way-to-count-the-number-of-values-in-the-same-field-separately/206721 "2019-11-06T04:45:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SeongHyun\_Kang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seonghyun_kang/32/45032_2.png) [@SeongHyun\_Kang](https://discuss.elastic.co/u/SeongHyun_Kang)\
**Post date:** [November 6, 2019, 4:45am UTC](https://discuss.elastic.co/t/in-elasticsearch-is-there-a-way-to-count-the-number-of-values-in-the-same-field-separately/206721/1 "2019-11-06T04:45:38Z")

</div>

```auto
name, action
A,go
B,stop
A,stop
C,stop

```

In elasticsearch, these values ​​are stored in the name and action fields.

What I want to get is to group each count in the action field by name and view them in table form.

```auto
name, go, stop
A, 1, 1
B, 0, 1
C, 0, 1

```

Finally is the type of table I want

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [November 18, 2019, 5:43pm UTC](https://discuss.elastic.co/t/in-elasticsearch-is-there-a-way-to-count-the-number-of-values-in-the-same-field-separately/206721/2 "2019-11-18T17:43:01Z")

</div>

You can use a count metric, with a split rows by name field.  
Then create 2 scripted fields:  
"go\_count" with the value of 1 if action is go and 0 if it's stop.  
"stop\_count" with the value of 0 if the action is go and 1 if it's stop.  
Then, in the original data table change the count metric to a sum metric of the "go\_count" field.  
Then add another sum metric on the "stop\_count" metric.

---

<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:** [December 16, 2019, 5:43pm UTC](https://discuss.elastic.co/t/in-elasticsearch-is-there-a-way-to-count-the-number-of-values-in-the-same-field-separately/206721/3 "2019-12-16T17:43:20Z")

</div>

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