# How to replace fields value

**URL:** <https://discuss.elastic.co/t/how-to-replace-fields-value/116746>\
**Category:** Kibana\
**Created:** [January 23, 2018, 7:59pm UTC](https://discuss.elastic.co/t/how-to-replace-fields-value/116746 "2018-01-23T19:59:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dr\_dob](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@dr\_dob](https://discuss.elastic.co/u/dr_dob)\
**Post date:** [January 23, 2018, 7:59pm UTC](https://discuss.elastic.co/t/how-to-replace-fields-value/116746/1 "2018-01-23T19:59:38Z")

</div>

Hi

I'm trying to automate the creation of scripted fields. For updating the "fields" field, it has a string value. So, I cant update it with "source": "ctx.\_source.fields.add(params.field)" by adding to the array. So what is the best way to update the field?

Is there a way to simply replace the field value with something like source": "ctx.\_source.fields = params.field"?

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [January 24, 2018, 3:58pm UTC](https://discuss.elastic.co/t/how-to-replace-fields-value/116746/2 "2018-01-24T15:58:09Z")

</div>

You should be able to just [update](https://www.elastic.co/guide/en/elasticsearch/reference/current/_modifying_your_data.html#_indexing_replacing_documents) the entire Index Pattern document with a new document that contains your updates

---

<div class="post-metadata">

**Author:** ![dr\_dob](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@dr\_dob](https://discuss.elastic.co/u/dr_dob)\
**Post date:** [January 25, 2018, 6:38pm UTC](https://discuss.elastic.co/t/how-to-replace-fields-value/116746/3 "2018-01-25T18:38:30Z")

</div>

I tried doing a partial update with the following:

curl -XPOST 'localhost:9200/.kibana/doc/index-pattern:5cd01980-e173-11e7-b90c-9930744e76ad/\_update?pretty' -H 'Content-Type: application/json' -d'  
{  
"script" : "ctx.\_source.index\u002Dpattern.title = \u0027pddd\u0027"  
}  
'

but it returned the following:

{  
"error" : {  
"root\_cause" : [  
{  
"type" : "remote\_transport\_exception",  
"reason" : "[\_Mtk082][127.0.0.1:9300][indices:data/write/update[s]]"  
}  
],  
"type" : "illegal\_argument\_exception",  
"reason" : "failed to execute script",  
"caused\_by" : {  
"type" : "script\_exception",  
"reason" : "compile error",  
"script\_stack" : [],  
"script" : "ctx.\_source.index-pattern.title = 'pddd'",  
"lang" : "painless",  
"caused\_by" : {  
"type" : "illegal\_argument\_exception",  
"reason" : "Left-hand side cannot be assigned a value."  
}  
}  
},  
"status" : 400  
}

Any ideas why?

---

<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:** [February 22, 2018, 6:39pm UTC](https://discuss.elastic.co/t/how-to-replace-fields-value/116746/4 "2018-02-22T18:39:14Z")

</div>

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