# Getting documents based on field length

**URL:** https://discuss.elastic.co/t/getting-documents-based-on-field-length/168178
**Category:** Elasticsearch
**Created:** [February 13, 2019, 10:05am UTC](https://discuss.elastic.co/t/getting-documents-based-on-field-length/168178 "2019-02-13T10:05:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![saqibjavid](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@saqibjavid](https://discuss.elastic.co/u/saqibjavid)
#### Post date: [February 13, 2019, 10:05am UTC](https://discuss.elastic.co/t/getting-documents-based-on-field-length/168178/1 "2019-02-13T10:05:25Z")

</div>

I have uploaded nearly 1,000,000 JSON files into elastic search. I am looking for a query which will help me filter and return documents based on a condition of field length using kibana.  
For example I have a field of phone numbers in my files, so I want to get only those files which consists of phone number length greater than 10, where (phone:) is the field. This must be done using kibana. Please assist me in it.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [February 13, 2019, 10:31am UTC](https://discuss.elastic.co/t/getting-documents-based-on-field-length/168178/2 "2019-02-13T10:31:47Z")

</div>

You should compute that value at index time. Like:

```auto
{
  "phone": "xyz",
  "phone_length": 3
}

```

You can do that at index time using a [painless script processor](https://www.elastic.co/guide/en/elasticsearch/reference/6.6/script-processor.html).

If you really want to run that at search time, you can use a [Script Query](https://www.elastic.co/guide/en/elasticsearch/reference/6.6/query-dsl-script-query.html). But this will be slow to run IMO.

---

<div class="post-metadata">

### Author: ![saqibjavid](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@saqibjavid](https://discuss.elastic.co/u/saqibjavid)
#### Post date: [February 13, 2019, 11:03am UTC](https://discuss.elastic.co/t/getting-documents-based-on-field-length/168178/3 "2019-02-13T11:03:40Z")

</div>

Can you give me a sample script query for retrieving the files with phone: whose length is greater than 10

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [February 13, 2019, 11:32am UTC](https://discuss.elastic.co/t/getting-documents-based-on-field-length/168178/4 "2019-02-13T11:32:46Z")

</div>

No sorry. I don't use Painless myself.

---

<div class="post-metadata">

### Author: ![saqibjavid](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@saqibjavid](https://discuss.elastic.co/u/saqibjavid)
#### Post date: [February 13, 2019, 12:01pm UTC](https://discuss.elastic.co/t/getting-documents-based-on-field-length/168178/5 "2019-02-13T12:01:02Z")

</div>

Thankyou so much @dadoonet

---

<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: [March 13, 2019, 12:01pm UTC](https://discuss.elastic.co/t/getting-documents-based-on-field-length/168178/6 "2019-03-13T12:01:03Z")

</div>

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