public async Task <bool> UpdateNotification(string samplePayload, NotificationFields notification) { string script = @"for (int i=0;i<ctx._source.fields.size();i++) { if (ctx._source.fields[i].ReferenceNumber == params.referenceNumber) { ctx._source.fields[i].Name=params.name; ctx._source.fields[i].ArName=params.arName; ctx._source.fields[i].SamplePayload=params.samplePayload; ctx._source.fields[i].Type=params.type; ctx._source.fields[i].ContentType=params.contentType; } }"; notification.SamplePayload = LoggingRepo.ObjectConverter.ContentType(samplePayload, notification.ContentType); var update = await _Client.UpdateByQueryAsync <NotificationDocument>(s => s.Index($"{IndexName}-*") .Script(q => q .Source(script) .Params(p => { p.Add("referenceNumber", notification.ReferenceNumber); p.Add("arName", notification.ArName); p.Add("name", notification.Name); p.Add("samplePayload", notification.SamplePayload); p.Add("type", notification.Type); p.Add("contentType", notification.ContentType); return(p); })) .Query(q => q .Match(m => m .Field(f => f.Suffix("fields.ReferenceNumber")) .Query(notification.ReferenceNumber))) ); return(update.Updated >= 1); }
public async Task <bool> AddNotification(string systemCode, string samplePayload, NotificationFields notification) { notification.SamplePayload = LoggingRepo.ObjectConverter.ContentType(samplePayload, notification.ContentType); var update = await _Client.UpdateByQueryAsync <NotificationDocument>(s => s.Index($"{IndexName}-*") .Script(q => q .Source("ctx._source['fields'].add(params.notificationStr);") .Params(p => p.Add("notificationStr", notification))) .Query(q => q .Match(m => m .Field(f => f.SystemCode) .Query(systemCode))) ); return(update.Updated >= 1); }