# How to filter docs by text field length?

**URL:** https://discuss.elastic.co/t/how-to-filter-docs-by-text-field-length/242941
**Category:** Elasticsearch
**Created:** [July 28, 2020, 4:29pm UTC](https://discuss.elastic.co/t/how-to-filter-docs-by-text-field-length/242941 "2020-07-28T16:29:46Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [August 3, 2020, 10:55am UTC](https://discuss.elastic.co/t/how-to-filter-docs-by-text-field-length/242941/2 "2020-08-03T10:55:01Z")

</div>

Using scripted fields is quite the performance killer in this example. The most performant solution to this would be to use an ingest pipeline with a [script processor](https://www.elastic.co/guide/en/elasticsearch/reference/7.8/script-processor.html) that stores the length of the string in a dedicated field.

The reason for the different values is that some data gets retrieved from the inverted index (where it already might have been shortened when there are long fields) where as the first one uses the JSON source.

---

_[View the full topic](https://discuss.elastic.co/t/how-to-filter-docs-by-text-field-length/242941)._
