# Creating script field using groovy - substring

**URL:** https://discuss.elastic.co/t/creating-script-field-using-groovy-substring/47788
**Category:** Elasticsearch
**Created:** [April 19, 2016, 12:33pm UTC](https://discuss.elastic.co/t/creating-script-field-using-groovy-substring/47788 "2016-04-19T12:33:11Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![suhae](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@suhae](https://discuss.elastic.co/u/suhae)
#### Post date: [April 19, 2016, 12:33pm UTC](https://discuss.elastic.co/t/creating-script-field-using-groovy-substring/47788/1 "2016-04-19T12:33:11Z")

</div>

Hi, i want to extract the part of String field.

that is,  
i want to classify paths : (A/B/C, A/B/D, A/B/E), (F/G/H), (F/I/A).  
but kibana classify (A/B/C), (A/B/D), (A/B/E), (F/G/H), (F/I/A) understandably..

so i have to use script in elasticsearch. (because kibana doesn't support non-numeric)  
first of all i queried this :  
curl -XGET 'localhost:9200/myaccess/\_search?pretty' -d '  
{  
"query" : {  
"filtered" : {  
"filter" : {  
"script" : {  
"script" : "doc['path'].value.substring(0,10)",  
"lang" : "groovy"  
}  
}  
}  
}  
}'

and i got this error :  
Caused by: ScriptException[failed to run inline script [doc[path].value.substring(0,5)] using lang [groovy]]; nested: MissingPropertyException[No such property: path for class: a72297f9c561c49dd73726e45411b0217a86e7db];

and 'path' field exist in myaccess index.  
 ![](https://us1.discourse-cdn.com/elastic/original/2X/0/08d35dc251b88315352f9f1d26eba91ffdac80eb.png)

is any problem in query? why this error occured?

---

<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 5, 2017, 10:57pm UTC](https://discuss.elastic.co/t/creating-script-field-using-groovy-substring/47788/2 "2017-07-05T22:57:51Z")

</div>


