# What is the correct and better way to get scripted fields in elastic query

**URL:** <https://discuss.elastic.co/t/what-is-the-correct-and-better-way-to-get-scripted-fields-in-elastic-query/138731>\
**Category:** Elasticsearch\
**Created:** [July 5, 2018, 1:42pm UTC](https://discuss.elastic.co/t/what-is-the-correct-and-better-way-to-get-scripted-fields-in-elastic-query/138731 "2018-07-05T13:42:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shoaib\_Mohommed](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Shoaib\_Mohommed](https://discuss.elastic.co/u/Shoaib_Mohommed)\
**Post date:** [July 5, 2018, 1:42pm UTC](https://discuss.elastic.co/t/what-is-the-correct-and-better-way-to-get-scripted-fields-in-elastic-query/138731/1 "2018-07-05T13:42:55Z")

</div>

Hi,

I am using below script for getting scripted fields and also in aggregation. and it works fine, but I was wondering if there is some other better way of doing this.

"script\_fields": {  
"CustomColumn1": {  
"script": " (( ((params.\_source['productDescription'].toLowerCase().indexOf('chain') \> -1)) )) ? ('ChainQuantity') : (( ((params.\_source['productDescription'].toLowerCase().indexOf('ribbon') \> -1)) )) ? ('Ribbon\_QTY') : 'blank'"  
}  
}

Please suggest

---

<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 2, 2018, 1:42pm UTC](https://discuss.elastic.co/t/what-is-the-correct-and-better-way-to-get-scripted-fields-in-elastic-query/138731/2 "2018-08-02T13:42:58Z")

</div>

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