Skip to content

Commit d562518

Browse files
committed
Deserialize error property on MultiGetHit
Closes #2871 (cherry picked from commit dbcfd94)
1 parent 92f2baa commit d562518

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

src/Nest/Document/Multiple/MultiGet/Response/MultiGetHit.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Newtonsoft.Json;
1+
using System;
2+
using Elasticsearch.Net;
3+
using System;
4+
using Newtonsoft.Json;
25

36
namespace Nest
47
{
@@ -20,6 +23,8 @@ public interface IMultiGetHit<out T> where T : class
2023

2124
string Routing { get; }
2225

26+
ServerError Error { get; }
27+
2328
long? Timestamp { get; }
2429

2530
long? Ttl { get; }
@@ -55,6 +60,9 @@ public class MultiGetHit<T> : IMultiGetHit<T>
5560
[JsonProperty("_routing")]
5661
public string Routing { get; internal set; }
5762

63+
[JsonProperty("error")]
64+
public ServerError Error { get; internal set; }
65+
5866
[JsonProperty("_timestamp")]
5967
public long? Timestamp { get; internal set; }
6068

src/Nest/Document/Multiple/MultiGet/Response/MultiGetResponse.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public interface IMultiGetResponse : IResponse
2525
[ContractJsonConverter(typeof(MultiGetHitJsonConverter))]
2626
public class MultiGetResponse : ResponseBase, IMultiGetResponse
2727
{
28+
public override bool IsValid => base.IsValid && !this._Documents.HasAny(d => d.Error != null);
29+
2830
public MultiGetResponse()
2931
{
3032
this._Documents = new List<IMultiGetHit<object>>();
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System;
2+
using System.Linq;
3+
using Elasticsearch.Net;
4+
using FluentAssertions;
5+
using Nest;
6+
using Tests.Framework;
7+
using Tests.Framework.ManagedElasticsearch.Clusters;
8+
using Tests.Framework.MockData;
9+
using Xunit;
10+
11+
namespace Tests.Reproduce
12+
{
13+
public class GithubIssue2871 : IClusterFixture<WritableCluster>
14+
{
15+
private readonly WritableCluster _cluster;
16+
17+
public GithubIssue2871(WritableCluster cluster) => _cluster = cluster;
18+
19+
[I]
20+
public void IsValidFalseAndDeserializedErrorsWhenMultiGetDocHasErrors()
21+
{
22+
var index1 = "index1";
23+
var index2 = "index2";
24+
var alias = "my_alias";
25+
var client = _cluster.Client;
26+
27+
client.CreateIndex(index1, c=> c
28+
.Mappings(m => m
29+
.Map<Project>(mm => mm
30+
.AutoMap()
31+
)
32+
)
33+
);
34+
35+
client.CreateIndex(index2, c => c
36+
.Mappings(m => m
37+
.Map<Project>(mm => mm
38+
.AutoMap()
39+
)
40+
)
41+
);
42+
43+
var projects = new[]
44+
{
45+
new Project { Name = "project1" },
46+
new Project { Name = "project2" },
47+
};
48+
49+
client.Bulk(b => b
50+
.IndexMany(projects, (bi, p) => bi.Index(index1).Document(p))
51+
.IndexMany(projects, (bi, p) => bi.Index(index2).Document(p))
52+
.Refresh(Refresh.WaitFor)
53+
);
54+
55+
client.Alias(a => a
56+
.Add(add => add
57+
.Alias(alias)
58+
.Index(index1)
59+
)
60+
.Add(add => add
61+
.Alias(alias)
62+
.Index(index2)
63+
)
64+
);
65+
66+
var multiGetRequest = new MultiGetRequest
67+
{
68+
Documents = new[] {
69+
new MultiGetOperation<Project>("project1") {Index = alias },
70+
new MultiGetOperation<Project>("project2") {Index = alias }
71+
}
72+
};
73+
74+
var response = client.MultiGet(multiGetRequest);
75+
response.ShouldNotBeValid();
76+
77+
var firstMultiGetHit = response.Documents.First();
78+
firstMultiGetHit.Error.Should().NotBeNull();
79+
firstMultiGetHit.Error.Error.Should().NotBeNull();
80+
firstMultiGetHit.Error.Error.Type.Should().NotBeNullOrEmpty();
81+
firstMultiGetHit.Error.Error.Reason.Should().NotBeNullOrEmpty();
82+
firstMultiGetHit.Error.Error.RootCause.Should().NotBeNull().And.HaveCount(1);
83+
84+
var lastMultiGetHit = response.Documents.Last();
85+
lastMultiGetHit.Error.Should().NotBeNull();
86+
lastMultiGetHit.Error.Error.Should().NotBeNull();
87+
lastMultiGetHit.Error.Error.Type.Should().NotBeNullOrEmpty();
88+
lastMultiGetHit.Error.Error.Reason.Should().NotBeNullOrEmpty();
89+
lastMultiGetHit.Error.Error.RootCause.Should().NotBeNull().And.HaveCount(1);
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)