# How do I count unique prefixes

**URL:** https://discuss.elastic.co/t/how-do-i-count-unique-prefixes/215751
**Category:** Kibana
**Created:** [January 20, 2020, 2:29pm UTC](https://discuss.elastic.co/t/how-do-i-count-unique-prefixes/215751 "2020-01-20T14:29:50Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Diwike](https://avatars.discourse-cdn.com/v4/letter/d/cab0a1/32.png) [@Diwike](https://discuss.elastic.co/u/Diwike)
#### Post date: [January 20, 2020, 2:29pm UTC](https://discuss.elastic.co/t/how-do-i-count-unique-prefixes/215751/1 "2020-01-20T14:29:50Z")

</div>

Hello, Im new to Kibana and this forum and hope to find some assistance.

Im trying to create a unique counter of the first five digits of, ex: 47001834023049820397402  
I can't for the life of me figure out how to do this.

In my data I have thousands of prefixes as, ex:  
57001834023049820397402  
47001834023049820397402  
24009700183402304982039

And I need to visualize how many of each prefix I have, ex:  
57001: 12  
47001: 9  
24009: 35

If anyone have a good way of doing this Id appreciate the help, thanks!

---

<div class="post-metadata">

### Author: ![azasypkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/azasypkin/32/42216_2.png) [@azasypkin](https://discuss.elastic.co/u/azasypkin)
#### Post date: [January 20, 2020, 3:06pm UTC](https://discuss.elastic.co/t/how-do-i-count-unique-prefixes/215751/2 "2020-01-20T15:06:28Z")

</div>

Hi @Diwike,

The first thing that comes into my mind is to create [a scripted field](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html), let's say `prefix` that would use `subsring` function under the hood, so that you can apply any aggregations (incl. count) on this new field.

Best,  
Oleg

---

<div class="post-metadata">

### Author: ![Diwike](https://avatars.discourse-cdn.com/v4/letter/d/cab0a1/32.png) [@Diwike](https://discuss.elastic.co/u/Diwike)
#### Post date: [January 24, 2020, 8:19am UTC](https://discuss.elastic.co/t/how-do-i-count-unique-prefixes/215751/3 "2020-01-24T08:19:32Z")

</div>

Thank you Aza,  
that sounds amazing but I don't even know where to start implementing your suggestion. If you have a moment I would greatly appreciate if you break it down a bit for me.

Thanks!

---

<div class="post-metadata">

### Author: ![azasypkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/azasypkin/32/42216_2.png) [@azasypkin](https://discuss.elastic.co/u/azasypkin)
#### Post date: [January 25, 2020, 12:22pm UTC](https://discuss.elastic.co/t/how-do-i-count-unique-prefixes/215751/4 "2020-01-25T12:22:07Z")

</div>

Sure, it'd would look something like this:

 ![prefix_short](https://us1.discourse-cdn.com/elastic/original/3X/8/d/8d1a3d64b8e685e05a92070f52748a0d5739c1d9.gif)

> [@Diwike](#):
>
> Thank you Aza,

Not `Aza`, but anyway 😉

Best,  
Oleg

---

<div class="post-metadata">

### Author: ![Diwike](https://avatars.discourse-cdn.com/v4/letter/d/cab0a1/32.png) [@Diwike](https://discuss.elastic.co/u/Diwike)
#### Post date: [February 10, 2020, 10:25am UTC](https://discuss.elastic.co/t/how-do-i-count-unique-prefixes/215751/5 "2020-02-10T10:25:10Z")

</div>

Wow that's amazing Oleg, thank you!

Ill try to replicate it from your guide.

Truly appreciate your support!

Daniel

---

<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: [March 9, 2020, 10:25am UTC](https://discuss.elastic.co/t/how-do-i-count-unique-prefixes/215751/6 "2020-03-09T10:25:16Z")

</div>

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