# Add Scripted fields through curl

**URL:** <https://discuss.elastic.co/t/add-scripted-fields-through-curl/134335>\
**Category:** Elasticsearch\
**Created:** [June 3, 2018, 7:31pm UTC](https://discuss.elastic.co/t/add-scripted-fields-through-curl/134335 "2018-06-03T19:31:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karanushah.1992](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@Karanushah.1992](https://discuss.elastic.co/u/Karanushah.1992)\
**Post date:** [June 3, 2018, 7:31pm UTC](https://discuss.elastic.co/t/add-scripted-fields-through-curl/134335/1 "2018-06-03T19:31:20Z")

</div>

Hi,

I want to add scripted field through curl.

I know I have to update .kibana index specifically the doc of that index pattern.

Below is the code that I am executing to add scripted field test in the index pattern pattern\_name

POST .kibana/doc/index-pattern:pattern\_name/\_update  
{  
"script": "ctx.\_source.new\_field ={'name':'test',  
'type':'number',  
'count':0,  
'scripted':true,  
'script':4150,  
'lang':'painless',  
'searchable':true,  
'aggregatable':true,  
'readFromDocValues':false}"  
}

I get the error saying  
"type": "illegal\_argument\_exception",  
"reason": "failed to execute script",  
"caused\_by": {  
"type": "script\_exception",  
"reason": "compile error",  
"script\_stack": [  
"ctx.\_source.new\_field = {'name':'test','type':'nu ...",  
" ^---- HERE"  
],  
"script": "ctx.\_source.new\_field = {'name':'test','type':'number','count':0,'scripted':true,'script':'4150','lang':'painless','searchable':true,'aggregatable':true,'readFromDocValues':false}",  
"lang": "painless",  
"caused\_by": {  
"type": "illegal\_argument\_exception",  
"reason": "invalid sequence of tokens near ['{'].",  
"caused\_by": {  
"type": "no\_viable\_alt\_exception",  
"reason": null  
}  
}  
}  
},  
"status": 400  
}

---

<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 1, 2018, 7:31pm UTC](https://discuss.elastic.co/t/add-scripted-fields-through-curl/134335/2 "2018-07-01T19:31:27Z")

</div>

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