Updating an document in a index


(mramaprasad) #1

I have the following mapping.
curl -XPUT 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' -d '
{
"productid":"1",
"category":"software"
}'

I am updating the document with the following

curl -XPOST '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?


(mramaprasad) #2

curl -XPOST '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'
{
"_index" : "cstest",
"_type" : "csproducts",
"_id" : "1",
"_version" : 4,
"found" : true, "_source" : {"productid":"1","productnumber":"123200","category":"softwaredevelopment"}
}

category is not saved as arrays.


(system) #3