# Painless Compile error

**URL:** <https://discuss.elastic.co/t/painless-compile-error/137847>\
**Category:** Elasticsearch\
**Created:** [June 28, 2018, 6:41pm UTC](https://discuss.elastic.co/t/painless-compile-error/137847 "2018-06-28T18:41:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RajiReddy](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@RajiReddy](https://discuss.elastic.co/u/RajiReddy)\
**Post date:** [June 28, 2018, 6:41pm UTC](https://discuss.elastic.co/t/painless-compile-error/137847/1 "2018-06-28T18:41:18Z")

</div>

HI, I am trying to get particular value from object array using painless but getting compile errors as below.

Error: Request to Elasticsearch failed: {"error":{"root\_cause":[{"type":"script\_exception","reason":"compile error","script\_stack":["GET bcbsm\_search/Authorizatio ..."," ^---- HERE"],"script":"GET bcbsm\_search/AuthorizationRequest/\_search?pretty\n{\n "query": {\n "function\_score": {\n "script\_score": {\n "script": {\n "lang": "painless",\n "source": """\n string BillingNPI ="";\n for (int i = 0; i \< doc['auth.providers'].length; ++i) {\n if(doc['auth.providers'][i].containsKey('Billing'))\n\t\t{\n\t\t\tBillingNPI = doc['auth.providers'][i].value;\n\t\t}\n }\n return BillingNPI;\n """\n }\n }\n }\n }\n}","lang":"painless"}],"type":"search\_phase\_execution\_exception","reason":"all shards failed","phase":"query","grouped":true,"failed\_shards":[{"shard":0,"index":"bcbsm\_search\_v5","node":"4qlJkrGHReuZtyHdNbxHxA","reason":{"type":"script\_exception","reason":"compile error","script\_stack":["GET bcbsm\_search/Authorizatio ..."," ^---- HERE"],"script":"GET bcbsm\_search/AuthorizationRequest/\_search?pretty\n{\n "query": {\n "function\_score": {\n "script\_score": {\n "script": {\n "lang": "painless",\n "source": """\n string BillingNPI ="";\n for (int i = 0; i \< doc['auth.providers'].length; ++i) {\n if(doc['auth.providers'][i].containsKey('Billing'))\n\t\t{\n\t\t\tBillingNPI = doc['auth.providers'][i].value;\n\t\t}\n }\n return BillingNPI;\n """\n }\n }\n }\n }\n}","lang":"painless","caused\_by":{"type":"illegal\_argument\_exception","reason":"unexpected token ['bcbsm\_search'] was expecting one of [{, ';'}]."}}}],"caused\_by":{"type":"script\_exception","reason":"compile error","script\_stack":["GET bcbsm\_search/Authorizatio ..."," ^---- HERE"],"script":"GET bcbsm\_search/AuthorizationRequest/\_search?pretty\n{\n "query": {\n "function\_score": {\n "script\_score": {\n "script": {\n "lang": "painless",\n "source": """\n string BillingNPI ="";\n for (int i = 0; i \< doc['auth.providers'].length; ++i) {\n if(doc['auth.providers'][i].containsKey('Billing'))\n\t\t{\n\t\t\tBillingNPI = doc['auth.providers'][i].value;\n\t\t}\n }\n return BillingNPI;\n """\n }\n }\n }\n }\n}","lang":"painless","caused\_by":{"type":"illegal\_argument\_exception","reason":"unexpected token ['bcbsm\_search'] was expecting one of [{, ';'}]."}}},"status":500}  
at [https://nlxesdev01.corp.cvscaremark.com:5601/bundles/kibana.bundle.js?v=14849:28:15872](https://nlxesdev01.corp.cvscaremark.com:5601/bundles/kibana.bundle.js?v=14849:28:15872)  
at Function.Promise.try ([https://nlxesdev01.corp.cvscaremark.com:5601/bundles/commons.bundle.js?v=14849:75:22403](https://nlxesdev01.corp.cvscaremark.com:5601/bundles/commons.bundle.js?v=14849:75:22403))  
at [https://nlxesdev01.corp.cvscaremark.com:5601/bundles/commons.bundle.js?v=14849:75:21773](https://nlxesdev01.corp.cvscaremark.com:5601/bundles/commons.bundle.js?v=14849:75:21773)  
at Array.map ()  
at Function.Promise.map ([https://nlxesdev01.corp.cvscaremark.com:5601/bundles/commons.bundle.js?v=14849:75:21728](https://nlxesdev01.corp.cvscaremark.com:5601/bundles/commons.bundle.js?v=14849:75:21728))  
at callResponseHandlers ([https://nlxesdev01.corp.cvscaremark.com:5601/bundles/kibana.bundle.js?v=14849:28:15484](https://nlxesdev01.corp.cvscaremark.com:5601/bundles/kibana.bundle.js?v=14849:28:15484))  
at [https://nlxesdev01.corp.cvscaremark.com:5601/bundles/kibana.bundle.js?v=14849:28:3614](https://nlxesdev01.corp.cvscaremark.com:5601/bundles/kibana.bundle.js?v=14849:28:3614)  
at processQueue ([https://nlxesdev01.corp.cvscaremark.com:5601/bundles/commons.bundle.js?v=14849:38:23621](https://nlxesdev01.corp.cvscaremark.com:5601/bundles/commons.bundle.js?v=14849:38:23621))  
at [https://nlxesdev01.corp.cvscaremark.com:5601/bundles/commons.bundle.js?v=14849:38:23888](https://nlxesdev01.corp.cvscaremark.com:5601/bundles/commons.bundle.js?v=14849:38:23888)  
at Scope.$eval ([https://nlxesdev01.corp.cvscaremark.com:5601/bundles/commons.bundle.js?v=14849:39:4619](https://nlxesdev01.corp.cvscaremark.com:5601/bundles/commons.bundle.js?v=14849:39:4619))

my script:

GET abc\_search/req/\_search?pretty  
{  
"query": {  
"function\_score": {  
"script\_score": {  
"script": {  
"lang": "painless",  
"source": """  
string BillingNPI ="";  
for (int i = 0; i \< doc['auth.providers'].length; ++i) {  
if(doc['auth.providers'][i].roleType = 'Billing')  
{  
BillingNPI = doc['auth.providers'][i].novologixProvider.nPI;  
}  
}  
return BillingNPI;  
"""  
}  
}  
}  
}  
}

Do you have any idea how to get rid of these errors

---

<div class="post-metadata">

**Author:** ![RajiReddy](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@RajiReddy](https://discuss.elastic.co/u/RajiReddy)\
**Post date:** [June 29, 2018, 5:22pm UTC](https://discuss.elastic.co/t/painless-compile-error/137847/2 "2018-06-29T17:22:41Z")

</div>

Got rid of this. Used painless script.

---

<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 27, 2018, 5:22pm UTC](https://discuss.elastic.co/t/painless-compile-error/137847/3 "2018-07-27T17:22:42Z")

</div>

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