# Unique count on field, not on field.keyword

**URL:** <https://discuss.elastic.co/t/unique-count-on-field-not-on-field-keyword/200417>\
**Category:** Kibana\
**Created:** [September 20, 2019, 12:40pm UTC](https://discuss.elastic.co/t/unique-count-on-field-not-on-field-keyword/200417 "2019-09-20T12:40:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dani\_Ruse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dani_ruse/32/54602_2.png) [@Dani\_Ruse](https://discuss.elastic.co/u/Dani_Ruse)\
**Post date:** [September 20, 2019, 12:40pm UTC](https://discuss.elastic.co/t/unique-count-on-field-not-on-field-keyword/200417/1 "2019-09-20T12:40:41Z")

</div>

Hello!

I am new to Kibana and I need to make a visualization showing the number of unique logs (with respect to the message).

The logs retrieved by my search/query contain a field called "message", all of them having the following structure: "Process started for person: 1234", where 1234 represents the unique ID of the person. The process can be started several times for the same person, so I need to count the unique number of persons for which the process started.

I tried to use an unique count aggregation, but I am only allowed by Kibana to choose the field "message.keyword" , but I need to uniquely count the entire message (or just the ending).

I tried to create a scripted field in order to split the message field, but I keep getting compiler errors and I honestly don't know where to display them (I'm just told by Kibana "Discover: Compile error").

How would you solve this?

Thanks in advance and sorry if the answer is obvious, but, as I've said, I'm a beginner.

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [September 20, 2019, 5:30pm UTC](https://discuss.elastic.co/t/unique-count-on-field-not-on-field-keyword/200417/2 "2019-09-20T17:30:27Z")

</div>

Only fields of type `keyword` can be used for unique count aggregations. This is because the entire field value is indexed as a single "keyword".

You can not do a unique count on the `message` field because each token (word) of the message field is indexed separately.

I am fairly certain the unique count on the `message.keyword` field will return the results you want.

---

<div class="post-metadata">

**Author:** ![Dani\_Ruse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dani_ruse/32/54602_2.png) [@Dani\_Ruse](https://discuss.elastic.co/u/Dani_Ruse)\
**Post date:** [September 23, 2019, 1:43pm UTC](https://discuss.elastic.co/t/unique-count-on-field-not-on-field-keyword/200417/3 "2019-09-23T13:43:13Z")

</div>

Thanks! You were right, message.keyword worked just fine, but the big difference between the total and the unique number appeared to big to be real. I checked manually and message.keyword seems to be working.

---

<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:** [October 21, 2019, 1:43pm UTC](https://discuss.elastic.co/t/unique-count-on-field-not-on-field-keyword/200417/4 "2019-10-21T13:43:13Z")

</div>

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