# Field - Limit length

**URL:** <https://discuss.elastic.co/t/field-limit-length/90954>\
**Category:** Logstash\
**Created:** [June 27, 2017, 12:23pm UTC](https://discuss.elastic.co/t/field-limit-length/90954 "2017-06-27T12:23:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![medley](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@medley](https://discuss.elastic.co/u/medley)\
**Post date:** [June 27, 2017, 12:23pm UTC](https://discuss.elastic.co/t/field-limit-length/90954/1 "2017-06-27T12:23:49Z")

</div>

Hello,

Is it possible to limit the length of a field ?

I am using Logstash 5.2.1.

M.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 27, 2017, 12:24pm UTC](https://discuss.elastic.co/t/field-limit-length/90954/2 "2017-06-27T12:24:44Z")

</div>

Yes, but I'm pretty sure no standard filter can do it. You'll have to use a ruby filter. I think examples of that have been posted here in the past.

---

<div class="post-metadata">

**Author:** ![medley](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@medley](https://discuss.elastic.co/u/medley)\
**Post date:** [June 27, 2017, 12:39pm UTC](https://discuss.elastic.co/t/field-limit-length/90954/3 "2017-06-27T12:39:37Z")

</div>

Yes I saw this in the previous posts

```
ruby {
       code => "
          event['message'] = event['message'][0..9999]
          event.tag 'long message'
       "
  }

```

However, when I start Logstash, I get this message :

```
Ruby exception occurred: Direct event field references (i.e. event['field']) have been disabled in favor of using event get and set methods (e.g. event.get('field')). Please consult the Logstash 5.0 breaking changes documentation for more details

```

But in the documentation, nothing about length limitation method.

M.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 27, 2017, 12:54pm UTC](https://discuss.elastic.co/t/field-limit-length/90954/4 "2017-06-27T12:54:12Z")

</div>

You need to use the new event API and replace `event[x]` with either `event.get(x)` or `event.set(x, y)`: [https://www.elastic.co/guide/en/logstash/current/event-api.html](https://www.elastic.co/guide/en/logstash/current/event-api.html)

---

<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 25, 2017, 12:54pm UTC](https://discuss.elastic.co/t/field-limit-length/90954/5 "2017-07-25T12:54:24Z")

</div>

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