{
"id":100,
"name":"xxx",
"others":{
"hobbies":["cricket","footbal"]
}}
You can user scripted update
(documentation link) for your requirement.
Query to add value in hobbiles
{
"script" : {
"source": "ctx._source.others.hobbies.add(params.hobby)",
"lang": "painless",
"params" : {
"hobby": "reading books"
}
}
}
Adding a new field in others
{
"script": {
"source": "ctx._source.others.location = 'value_of_new_field'",
"lang": "painless"
}
}
Remove cricket from hobbies
{
"script" : {
"source": "int index = ctx._source.others.hobbies.indexOf(params.remove_string); if(index != -1){ctx._source.others.hobbies.remove(index);}",
"lang": "painless",
"params" : {
"remove_string" : "cricket"
}
}
}
UPDATE-1 As per asked in comments below is way to add an array field.
Adding an array field
{
"script": {
"source": "ctx._source.extra.location = []",
"lang": "painless"
}
}