# Updating an document in a index

**URL:** https://discuss.elastic.co/t/updating-an-document-in-a-index/32419
**Category:** Elasticsearch
**Created:** [October 16, 2015, 9:46pm UTC](https://discuss.elastic.co/t/updating-an-document-in-a-index/32419 "2015-10-16T21:46:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mramaprasad](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@mramaprasad](https://discuss.elastic.co/u/mramaprasad)
#### Post date: [October 16, 2015, 9:46pm UTC](https://discuss.elastic.co/t/updating-an-document-in-a-index/32419/1 "2015-10-16T21:46:05Z")

</div>

I have the following mapping.  
curl -XPUT [http://localhost:9200/cstest/](http://localhost:9200/cstest/) -d '  
{  
"mappings": {  
"csproducts" : {  
"properties" : {   
"productid":{  
"type" : "String"   
},   
"category":{  
"type": "string",  
"null\_value" : "N/A"   
}  
} //end properties  
} //end csproducts  
} //end mapping  
}  
'  
Data:  
curl -XPUT '[http://localhost:9200/cstest/csproducts/1](http://localhost:9200/cstest/csproducts/1)' -d '  
{  
"productid":"1",  
"category":"software"  
}'

I am updating the document with the following

curl -XPOST '[http://localhost:9200/cstest/csproducts/1](http://localhost:9200/cstest/csproducts/1)' -d'  
{  
"script" : "ctx.\_source.category+=new\_category",  
"params" : {  
"new\_category" : "development"  
}  
}'

I need to insert another category called "development" to the the category array.  
This does not seem to be working. Any idea how to do it?

---

<div class="post-metadata">

### Author: ![mramaprasad](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@mramaprasad](https://discuss.elastic.co/u/mramaprasad)
#### Post date: [October 16, 2015, 10:12pm UTC](https://discuss.elastic.co/t/updating-an-document-in-a-index/32419/2 "2015-10-16T22:12:30Z")

</div>

curl -XPOST '[http://localhost:9200/cstest/csproducts/1/\_update](http://localhost:9200/cstest/csproducts/1/_update)' -d'  
{  
"script" : "ctx.\_source.category+=new\_category",  
"params" : {  
"new\_category" : "development"  
}  
}'

Updates the data but it looks like  
curl -XGET '[http://localhost:9200/cstest/csproducts/1?pretty=true](http://localhost:9200/cstest/csproducts/1?pretty=true)'  
{  
"\_index" : "cstest",  
"\_type" : "csproducts",  
"\_id" : "1",  
"\_version" : 4,  
"found" : true, "\_source" : {"productid":"1","productnumber":"123200","category":"softwaredevelopment"}  
}

category is not saved as arrays.

---

<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, 11:44pm UTC](https://discuss.elastic.co/t/updating-an-document-in-a-index/32419/3 "2017-07-05T23:44:16Z")

</div>


