Skip to content

Commit d5d85d5

Browse files
committed
Reverted previous commits
1 parent a944575 commit d5d85d5

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/Elasticsearch/Repositories/ElasticRepositoryBase.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,28 @@ public async Task RemoveAsync(ICollection<T> documents, bool sendNotification =
7878
await OnDocumentsRemovingAsync(documents).AnyContext();
7979

8080
var documentsByIndex = documents.GroupBy(d => GetDocumentIndexFunc?.Invoke(d)).ToList();
81-
foreach (var group in documentsByIndex.Where(g => String.IsNullOrEmpty(g.Key))) {
82-
var response = await Context.ElasticClient.DeleteByQueryAsync<T>(q => q.Query(q1 => q1.Ids(group.Select(d => d.Id))).Index(group.Key)).AnyContext();
83-
if (!response.IsValid)
84-
throw new ApplicationException(String.Join("\r\n", response.ServerError?.Error, response.ConnectionStatus.OriginalException));
85-
}
86-
87-
var indexedDocuments = documentsByIndex.Where(g => !String.IsNullOrEmpty(g.Key)).ToList();
88-
if (indexedDocuments.Count > 0) {
89-
var response = await Context.ElasticClient.BulkAsync(bulk => {
90-
foreach (var group in indexedDocuments)
91-
bulk.DeleteMany(group.Select(g => g.Id), (b, id) => b.Index(group.Key));
92-
93-
return bulk;
94-
}).AnyContext();
95-
96-
if (!response.IsValid)
97-
throw new ApplicationException(String.Join("\r\n", response.ItemsWithErrors.Select(i => i.Error)), response.ConnectionStatus.OriginalException);
98-
}
81+
foreach (var g in documentsByIndex)
82+
await Context.ElasticClient.DeleteByQueryAsync<T>(q => q.Query(q1 => q1.Ids(g.Select(d => d.Id))).Index(g.Key)).AnyContext();
83+
84+
// TODO: Add tests and ensure we can bulk delete.
85+
//foreach (var group in documentsByIndex.Where(g => String.IsNullOrEmpty(g.Key))) {
86+
// var response = await Context.ElasticClient.DeleteByQueryAsync<T>(q => q.Query(q1 => q1.Ids(group.Select(d => d.Id))).Index(group.Key)).AnyContext();
87+
// if (!response.IsValid)
88+
// throw new ApplicationException(String.Join("\r\n", response.ServerError?.Error, response.ConnectionStatus.OriginalException));
89+
//}
90+
91+
//var indexedDocuments = documentsByIndex.Where(g => !String.IsNullOrEmpty(g.Key)).ToList();
92+
//if (indexedDocuments.Count > 0) {
93+
// var response = await Context.ElasticClient.BulkAsync(bulk => {
94+
// foreach (var group in indexedDocuments)
95+
// bulk.DeleteMany(group.Select(g => g.Id), (b, id) => b.Index(group.Key));
96+
97+
// return bulk;
98+
// }).AnyContext();
99+
100+
// if (!response.IsValid)
101+
// throw new ApplicationException(String.Join("\r\n", response.ItemsWithErrors.Select(i => i.Error)), response.ConnectionStatus.OriginalException);
102+
//}
99103

100104
await OnDocumentsRemovedAsync(documents, sendNotification).AnyContext();
101105
}

0 commit comments

Comments
 (0)