Skip to content

Commit 99a2e26

Browse files
committed
Fix #1146: extend DeleteResponse to handle delete by query as well
This is a temporary fix for BWC purposes until we can create a separate response object for delete by query requests in 2.0.
1 parent b2c05e1 commit 99a2e26

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,90 @@
11
using Newtonsoft.Json;
2+
using System.Collections.Generic;
23

34
namespace Nest
45
{
6+
// TODO: For backwards compatibility, this class acts as the response object
7+
// for both delete and delete by query requests, even though their actual responses
8+
// are completely different. For 2.0, we should move the delete by query specific
9+
// properties to a separate object (DeleteByQueryResponse).
10+
// See: https://github.com/elasticsearch/elasticsearch-net/issues/1146
511
public interface IDeleteResponse : IResponse
612
{
13+
/// <summary>
14+
/// The ID of the deleted document.
15+
/// NOTE: This property only applies to delete requests and will be
16+
/// null for delete by query.
17+
/// </summary>
718
string Id { get; }
19+
20+
/// <summary>
21+
/// The index of the deleted document.
22+
/// NOTE: This property only applies to delete requests and will be
23+
/// null for delete by query.
24+
/// </summary>
825
string Index { get; }
26+
27+
/// <summary>
28+
/// The type of the deleted document.
29+
/// NOTE: This property only applies to delete requests and will be
30+
/// null for delete by query.
31+
/// </summary>
932
string Type { get; }
33+
34+
/// <summary>
35+
/// The version of the deleted document.
36+
/// NOTE: This property only applies to delete requests and will be
37+
/// null for delete by query.
38+
/// </summary>
1039
string Version { get; }
40+
41+
/// <summary>
42+
/// Whether or not the document was found and deleted from the index.
43+
/// NOTE: This property only applies to delete requests and will be
44+
/// false for delete by query.
45+
/// </summary>
1146
bool Found { get; }
47+
48+
#region DeleteByQuery properties
49+
50+
/// <summary>
51+
/// The delete by query details for each affected index.
52+
/// NOTE: This property only applies to delete by query requests and
53+
/// will be null for delete requests.
54+
/// </summary>
55+
IDictionary<string, DeleteByQueryIndices> Indices { get; set; }
56+
57+
#endregion
1258
}
1359

60+
1461
[JsonObject]
1562
public class DeleteResponse : BaseResponse, IDeleteResponse
1663
{
1764
[JsonProperty("_index")]
1865
public string Index { get; internal set; }
66+
1967
[JsonProperty("_type")]
2068
public string Type { get; internal set; }
69+
2170
[JsonProperty("_id")]
2271
public string Id { get; internal set; }
72+
2373
[JsonProperty("_version")]
2474
public string Version { get; internal set; }
75+
2576
[JsonProperty("found")]
2677
public bool Found { get; internal set; }
78+
79+
[JsonProperty("_indices")]
80+
[JsonConverter(typeof(DictionaryKeysAreNotPropertyNamesJsonConverter))]
81+
public IDictionary<string, DeleteByQueryIndices> Indices { get; set; }
82+
}
2783

84+
[JsonObject]
85+
public class DeleteByQueryIndices
86+
{
87+
[JsonProperty("_shards")]
88+
public ShardsMetaData Shards { get; set; }
2889
}
2990
}

src/Tests/Nest.Tests.Integration/Core/DeleteTests.cs

+22
Original file line numberDiff line numberDiff line change
@@ -328,5 +328,27 @@ public void RemoveAllByQueryOverIndices()
328328
Assert.Greater(countResult.Count, 0);
329329

330330
}
331+
332+
[Test]
333+
public void DeleteByQuery()
334+
{
335+
var response = this.Client.DeleteByQuery<ElasticsearchProject>(d => d
336+
.Query(q => q
337+
.Match(m => m
338+
.OnField(p => p.Name)
339+
.Query("elasticsearch")
340+
)
341+
)
342+
);
343+
344+
response.IsValid.Should().BeTrue();
345+
response.Indices.Should().NotBeNull();
346+
response.Indices.Should().ContainKey(ElasticsearchConfiguration.DefaultIndex);
347+
348+
var indexDetails = response.Indices[ElasticsearchConfiguration.DefaultIndex];
349+
indexDetails.Should().NotBeNull();
350+
indexDetails.Shards.Successful.Should().BeGreaterThan(0);
351+
indexDetails.Shards.Failed.Should().Be(0);
352+
}
331353
}
332354
}

0 commit comments

Comments
 (0)