# Scripted field to count occurence in string does not work

**URL:** <https://discuss.elastic.co/t/scripted-field-to-count-occurence-in-string-does-not-work/131826>\
**Category:** Elasticsearch\
**Created:** [May 14, 2018, 11:54pm UTC](https://discuss.elastic.co/t/scripted-field-to-count-occurence-in-string-does-not-work/131826 "2018-05-14T23:54:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hendo\_Lim](https://avatars.discourse-cdn.com/v4/letter/h/ed655f/32.png) [@Hendo\_Lim](https://discuss.elastic.co/u/Hendo_Lim)\
**Post date:** [May 14, 2018, 11:54pm UTC](https://discuss.elastic.co/t/scripted-field-to-count-occurence-in-string-does-not-work/131826/1 "2018-05-14T23:54:09Z")

</div>

Hi, I am trying to create a scripted field on Kibana for counting the number occurrences of slash ('/') character inside a string field like so:  
`doc['my_field.keyword']?.value?.count('/')`  
But 'discover' page throws me 'Courier Fetch: 5 of 15 shards failed.' and is not able to show any data (No result found).

I have another scripted field that is just for counting the length of that same field like so:  
`doc['my_field.keyword']?.value?.length()`  
And it works fine. Which means there is nothing wrong with that field but perhaps the 'count' method is not supported in scripted field?

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [May 16, 2018, 3:43am UTC](https://discuss.elastic.co/t/scripted-field-to-count-occurence-in-string-does-not-work/131826/2 "2018-05-16T03:43:41Z")

</div>

There is no such thing as a `count` method. You need to implement this count using your own algorithm.

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [June 12, 2018, 9:01pm UTC](https://discuss.elastic.co/t/scripted-field-to-count-occurence-in-string-does-not-work/131826/4 "2018-06-12T21:01:29Z")

</div>

> [@gregpaskal](#):
>
> What a strange this to be missing from the string manipulation capabilities.

Painless is limited to what Java can provide in terms of API.

---

<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 10, 2018, 9:01pm UTC](https://discuss.elastic.co/t/scripted-field-to-count-occurence-in-string-does-not-work/131826/5 "2018-07-10T21:01:30Z")

</div>

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