# How to get a field value greater than 50 characters

**URL:** https://discuss.elastic.co/t/how-to-get-a-field-value-greater-than-50-characters/138982
**Category:** Elasticsearch
**Created:** [July 6, 2018, 9:29pm UTC](https://discuss.elastic.co/t/how-to-get-a-field-value-greater-than-50-characters/138982 "2018-07-06T21:29:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![thinkdffrnt](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@thinkdffrnt](https://discuss.elastic.co/u/thinkdffrnt)
#### Post date: [July 6, 2018, 9:29pm UTC](https://discuss.elastic.co/t/how-to-get-a-field-value-greater-than-50-characters/138982/1 "2018-07-06T21:29:28Z")

</div>

ES version 6.1.1

Mapping  
"fieldName": {  
"type": "keyword"  
}

---

<div class="post-metadata">

### Author: ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)
#### Post date: [July 9, 2018, 12:38pm UTC](https://discuss.elastic.co/t/how-to-get-a-field-value-greater-than-50-characters/138982/2 "2018-07-09T12:38:35Z")

</div>

Do you want to query your data for documents that contain a field with more than 50 characters? You can use a script for that.

For example, a script query ([https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-query.html)), that calculates the length of the field and returns `true` if the field has more than 50 characters.

One warning: script queries work well for queries that you do not use too often. Script queries are generally expensive, so you want to use them as little as possible.

If you want to query on the length of the field a lot, it's better to pre-process your documents when you index them, and calculate the length of the field then. You could use the ingest node functionality for that ([https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html)) with a script processor ([https://www.elastic.co/guide/en/elasticsearch/reference/current/script-processor.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/script-processor.html)) that calculates the length of `fieldName` and adds the result as a value of a new field in your documents. You can then use a simple `range` query on that calculated field.

---

<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: [August 6, 2018, 12:38pm UTC](https://discuss.elastic.co/t/how-to-get-a-field-value-greater-than-50-characters/138982/3 "2018-08-06T12:38:36Z")

</div>

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