Getting documents based on field length

(Mohammed Saqib ) #1

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.

(David Pilato) #2

You should compute that value at index time. Like:

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

You can do that at index time using a painless script processor.

If you really want to run that at search time, you can use a Script Query. But this will be slow to run IMO.

(Mohammed Saqib ) #3

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

(David Pilato) #4

No sorry. I don't use Painless myself.

(Mohammed Saqib ) #5

Thankyou so much @dadoonet

(system) closed #6

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