|
| 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