I am trying to update an existing indexed document. I have indexed tags, title and owners field. Now when the user changes the title, I need to find and update the document
also using Nest 7.x.
If you want to do only a partial update, you can use this method that worked great for me. You must specify "T, K" where T is the full object and K the partial object. Creating a POCO for every partial update is kind of overwork and annoying. For this issue, you can use anonymous object like so
public bool PartialUpdate(string id, object entity)
{
var result = _elasticClient.Update(DocumentPath.Id(id), i => i.Index(_indexName).Doc(entity));
return result.IsValid;
}
Im using the Elastic Common Schema, so here is an example of a partial object for the update:
new
{
Labels = new Dictionary
{
{ "EscalateTo", alert.AlertState == AlertState.Escalation ? escalationId : "" },
{ "EscalateFrom", alert.AlertState == AlertState.Descalation ? escalationId : "" },
},
Event = new
{
End = alert.WindowEnd,
Duration = (alert.WindowEnd - storedAlert.StartTime.Value).Ticks
}
};