diff --git a/src/Nest.Tests.Integration/Core/Bulk/BulkTests.cs b/src/Nest.Tests.Integration/Core/Bulk/BulkTests.cs index ed452c33467..7b78c243c29 100644 --- a/src/Nest.Tests.Integration/Core/Bulk/BulkTests.cs +++ b/src/Nest.Tests.Integration/Core/Bulk/BulkTests.cs @@ -12,8 +12,8 @@ public class BulkTests : IntegrationTests { [Test] public void Bulk() - { - //Detete so we know the create does not throw an error. + { + //Delete so we know the create does not throw an error. this._client.DeleteIndex(ElasticsearchConfiguration.DefaultIndex); var result = this._client.Bulk(b => b .Index(i => i.Object(new ElasticSearchProject {Id = 2})) @@ -24,8 +24,8 @@ public void Bulk() result.IsValid.Should().BeTrue(); result.Items.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(3).And.OnlyContain(r => r.OK); - var deleteResponses = result.Items.OfType(); - var createResponses = result.Items.OfType(); + var deleteResponses = result.Items.OfType(); + var createResponses = result.Items.OfType(); var indexResponses = result.Items.OfType(); deleteResponses.Should().HaveCount(1); @@ -41,12 +41,12 @@ public void Bulk() indexResponses.Should().HaveCount(1); indexResponses.First().Id.Should().BeEquivalentTo("2"); indexResponses.First().Index.Should().BeEquivalentTo(ElasticsearchConfiguration.DefaultIndex); - indexResponses.First().Type.Should().BeEquivalentTo(this.GetTypeNameFor()); + indexResponses.First().Type.Should().BeEquivalentTo(this.GetTypeNameFor()); } [Test] public void BulkWithFixedIndex() - { + { var indexName = ElasticsearchConfiguration.NewUniqueIndexName(); var result = this._client.Bulk(b => b .FixedPath(indexName, "mytype") @@ -116,7 +116,7 @@ public void BulkWithFixedIndexOveriddenIndividualy() [Test] public void BulkAlternativeWayOfWriting() { - this._client.DeleteIndex(ElasticsearchConfiguration.DefaultIndex); + this._client.DeleteIndex(ElasticsearchConfiguration.DefaultIndex); var descriptor = new BulkDescriptor(); foreach (var i in Enumerable.Range(0, 1000)) @@ -128,7 +128,60 @@ public void BulkAlternativeWayOfWriting() result.Items.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(1000).And.OnlyContain(r => r.OK); - } + } + + [Test] + public void BulkIndexWithPercolate() + { + // register up some percolator queries to test matching + var query1 = "bulkindex-test-doc-1"; + + this._client.UnregisterPercolator(query1); + + var perc = this._client.RegisterPercolator(p => p + .Name(query1) + .Query(q => q + .Term(f => f.Country, "netherlands") + ) + ); + + var descriptor = new BulkDescriptor(); + + // match against any doc + descriptor.Index(i => i + .Object(new ElasticSearchProject { Id = 2, Country = "netherlands" }) + .Percolate("*") // match on any percolated docs + ); + + // no percolate requested this time + descriptor.Index(i => i + .Object(new ElasticSearchProject { Id = 3, Country = "netherlands" }) + ); + + var result = this._client.Bulk(descriptor); + + result.Should().NotBeNull(); + result.IsValid.Should().BeTrue(); + + result.Items.Should().NotBeNull().And.NotBeEmpty().And.HaveCount(2).And.OnlyContain(r => r.OK); + var indexResponses = result.Items.OfType(); + + // tests on percolated responses + indexResponses.Should().HaveCount(2); + + indexResponses.First().Id.Should().BeEquivalentTo("2"); + indexResponses.First().Index.Should().BeEquivalentTo(ElasticsearchConfiguration.DefaultIndex); + indexResponses.First().Type.Should().BeEquivalentTo(this.GetTypeNameFor()); + indexResponses.First().Matches.Should().NotBeNull(); + + indexResponses.ElementAt(1).Id.Should().BeEquivalentTo("3"); + indexResponses.ElementAt(1).Index.Should().BeEquivalentTo(ElasticsearchConfiguration.DefaultIndex); + indexResponses.ElementAt(1).Type.Should().BeEquivalentTo(this.GetTypeNameFor()); + indexResponses.First().Matches.Should().BeNull(); + + // cleanup + this._client.UnregisterPercolator(query1); + } } } diff --git a/src/Nest/Domain/Responses/BulkIndexResponseItem.cs b/src/Nest/Domain/Responses/BulkIndexResponseItem.cs index f2962620568..dae2c261d6a 100644 --- a/src/Nest/Domain/Responses/BulkIndexResponseItem.cs +++ b/src/Nest/Domain/Responses/BulkIndexResponseItem.cs @@ -1,4 +1,5 @@ -using Nest.Resolvers.Converters; +using System.Collections.Generic; +using Nest.Resolvers.Converters; using Newtonsoft.Json; namespace Nest @@ -20,5 +21,11 @@ public class BulkIndexResponseItem : BulkOperationResponseItem public override bool OK { get; internal set; } [JsonProperty("error")] public override string Error { get; internal set; } + + /// + /// Null if Percolation was not requested while indexing this doc, otherwise returns the percolator _ids that matched (if any) + /// + [JsonProperty(PropertyName = "matches")] + public IEnumerable Matches { get; internal set; } } } \ No newline at end of file