# Get a length/size of message field value

**URL:** <https://discuss.elastic.co/t/get-a-length-size-of-message-field-value/254368>\
**Category:** Kibana\
**Created:** [November 5, 2020, 8:14am UTC](https://discuss.elastic.co/t/get-a-length-size-of-message-field-value/254368 "2020-11-05T08:14:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![EugeneZ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugenez/32/78447_2.png) [@EugeneZ](https://discuss.elastic.co/u/EugeneZ)\
**Post date:** [November 5, 2020, 8:14am UTC](https://discuss.elastic.co/t/get-a-length-size-of-message-field-value/254368/1 "2020-11-05T08:14:03Z")

</div>

Hi, I try to make a scripted fields with size of message field value. I tried

```auto
doc['message'].value.getSize() 
doc['message'].value.size()

```

I tried also with `['message.keyword'] ` but nothing. I have in preview. Where am I wrong?  
Thank you

---

<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, 9:40am UTC](https://discuss.elastic.co/t/get-a-length-size-of-message-field-value/254368/2 "2020-11-05T09:40:38Z")

</div>

Hi @EugeneZ,

I tried with a sample data and it works with `length`: `doc['category.keyword'].value.length()`

Let me know if that fixed your problem!

---

<div class="post-metadata">

**Author:** ![EugeneZ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugenez/32/78447_2.png) [@EugeneZ](https://discuss.elastic.co/u/EugeneZ)\
**Post date:** [November 5, 2020, 9:47am UTC](https://discuss.elastic.co/t/get-a-length-size-of-message-field-value/254368/3 "2020-11-05T09:47:50Z")

</div>

Hmm...  
I try `return doc['message.keyword'].value.length()` and in preview I have

```auto
[
 {
  "_id": "R7h8RXUBp5UPtyZb69B4",
  "sf_msg_size": [
   63
  ]
 },
 {
  "_id": "SLh8RXUBp5UPtyZb69B4",
  "sf_msg_size": [
   63
  ]
 },

```

It is somethig but not 'message' length.

---

<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, 9:58am UTC](https://discuss.elastic.co/t/get-a-length-size-of-message-field-value/254368/4 "2020-11-05T09:58:21Z")

</div>

What's the expected outcome then? For me it works perfectly, eg. for the example I gave, it returns

```auto
[
 {
  "_id": "WmrTl3UB9Atbtm2uF-nb",
  "scripted_len": [
   13
  ]
 }...
 ]

```

And my first result is `Women's Clothing` which is 13 characters long.

---

<div class="post-metadata">

**Author:** ![EugeneZ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugenez/32/78447_2.png) [@EugeneZ](https://discuss.elastic.co/u/EugeneZ)\
**Post date:** [November 5, 2020, 10:02am UTC](https://discuss.elastic.co/t/get-a-length-size-of-message-field-value/254368/5 "2020-11-05T10:02:14Z")

</div>

Yes, it's working. Thank you.

---

<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, 10:02am UTC](https://discuss.elastic.co/t/get-a-length-size-of-message-field-value/254368/6 "2020-12-03T10:02:14Z")

</div>

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