I am using ES 5.5.
Here is what I am stuck at.
I am able to add new nested array element.
But I also need to update any existing ones.
my mapping
{
"email_misc": {
"mappings": {
"emails": {
"properties": {
"email": {
"type": "text"
},
"email_data": {
"type": "nested",
"properties": {
"created_time": {
"type": "long"
},
"direct_email": {
"type": "integer"
},
"email_id": {
"type": "long"
},
"email_identifier": {
"type": "text"
},
"email_priority": {
"type": "integer"
},
"email_sent": {
"type": "integer"
},
"email_subject": {
"type": "text"
},
"mg_key": {
"type": "text"
},
"recipient_email": {
"type": "keyword"
},
"recipient_name": {
"type": "text"
},
"status_bounced": {
"type": "integer"
},
"status_clicked": {
"type": "integer"
},
"status_complained": {
"type": "integer"
},
"status_delivered": {
"type": "integer"
},
"status_dropped": {
"type": "integer"
},
"status_opened": {
"type": "integer"
},
"status_unsubscribed": {
"type": "integer"
}
}
},
"email_key": {
"type": "keyword"
},
"recipient_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
I have a record like
i want to update the status a nested record
I tried
{
"script": "for (int i = 0; i < ctx._source.email_data.size();i++){if(ctx._source.email_data[i].email_id == params.id){ctx._source.email_data.remove(i);i--;}}",
"params": {
"id": 165
}
}
gave me
but not data is removed.
I also tried
{
"script": "for (int i = 0; i < ctx._source.email_data.size(); i++){if(ctx._source.email_data[i].email_id == params.remove_id){ctx._source.email_data[i].email_subject = 'Updated John';}}",
"params": {
"id": 165
}
}
ALSO gave me success but nothing was updated.
what is the correct way to do it.
thank you