@@ -78,24 +78,28 @@ public async Task RemoveAsync(ICollection<T> documents, bool sendNotification =
78
78
await OnDocumentsRemovingAsync ( documents ) . AnyContext ( ) ;
79
79
80
80
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
+ //}
99
103
100
104
await OnDocumentsRemovedAsync ( documents , sendNotification ) . AnyContext ( ) ;
101
105
}
0 commit comments