# For length parameter in scripted fields its returning length of unique values in a doc

**URL:** <https://discuss.elastic.co/t/for-length-parameter-in-scripted-fields-its-returning-length-of-unique-values-in-a-doc/254393>\
**Category:** Kibana\
**Created:** [November 5, 2020, 11:18am UTC](https://discuss.elastic.co/t/for-length-parameter-in-scripted-fields-its-returning-length-of-unique-values-in-a-doc/254393 "2020-11-05T11:18:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pranusha119](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@Pranusha119](https://discuss.elastic.co/u/Pranusha119)\
**Post date:** [November 5, 2020, 11:18am UTC](https://discuss.elastic.co/t/for-length-parameter-in-scripted-fields-its-returning-length-of-unique-values-in-a-doc/254393/1 "2020-11-05T11:18:11Z")

</div>

Hello,

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/5/95503e4f8be7708eb11f5dc0cb189ad19e2b01a1.png)

Length of string is 5 , but why is it returning 3 by counting only unique characters ?

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/9/49cc775b8b9f7934ab8b3c8fc16a496781938433.png)

Same with words in a string

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [November 5, 2020, 11:25am UTC](https://discuss.elastic.co/t/for-length-parameter-in-scripted-fields-its-returning-length-of-unique-values-in-a-doc/254393/2 "2020-11-05T11:25:36Z")

</div>

Hi @Pranusha119,

try `doc['special_char.keyword'].value.length()`

Let me know if that's what you expect to get.

---

<div class="post-metadata">

**Author:** ![Pranusha119](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@Pranusha119](https://discuss.elastic.co/u/Pranusha119)\
**Post date:** [November 5, 2020, 11:35am UTC](https://discuss.elastic.co/t/for-length-parameter-in-scripted-fields-its-returning-length-of-unique-values-in-a-doc/254393/3 "2020-11-05T11:35:36Z")

</div>

Hi @Marta_Bondyra

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/e/1eba1d22ef6cedd30ebbff06cecf3830d55dcc99.png)

It's retuning 1 instead of 5

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [November 5, 2020, 1:38pm UTC](https://discuss.elastic.co/t/for-length-parameter-in-scripted-fields-its-returning-length-of-unique-values-in-a-doc/254393/4 "2020-11-05T13:38:16Z")

</div>

Oh ok, sorry, I didn't understand your question before – unfortunately, to my knowledge you cannot do it – once you index your field as keyword, it will only count unique values. Maybe you could add a string field at indexing time that would store all the characters as a string and then you could print out the string length?

I don't have any other ideas, maybe someone else has.

---

<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 3, 2020, 1:38pm UTC](https://discuss.elastic.co/t/for-length-parameter-in-scripted-fields-its-returning-length-of-unique-values-in-a-doc/254393/5 "2020-12-03T13:38:22Z")

</div>

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