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

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.

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

Finally is the type of table I want

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.

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