diff --git a/src/Nest/Domain/Responses/UpdateResponse.cs b/src/Nest/Domain/Responses/UpdateResponse.cs index 673608ea8cd..d47b9f940ad 100644 --- a/src/Nest/Domain/Responses/UpdateResponse.cs +++ b/src/Nest/Domain/Responses/UpdateResponse.cs @@ -1,4 +1,6 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Nest.Domain; +using Newtonsoft.Json; namespace Nest { @@ -9,6 +11,10 @@ public interface IUpdateResponse : IResponse string Type { get; } string Id { get; } string Version { get; } + GetFromUpdate Get { get; } + + T Source() where T : class; + FieldSelection Fields() where T : class; } [JsonObject] @@ -25,5 +31,36 @@ public class UpdateResponse : BaseResponse, IUpdateResponse public string Id { get; private set; } [JsonProperty(PropertyName = "_version")] public string Version { get; private set; } + + [JsonProperty(PropertyName = "get")] + public GetFromUpdate Get { get; private set; } + + public T Source() where T : class + { + if (this.Get == null) return null; + return this.Get.Source.As(); + } + + public FieldSelection Fields() where T : class + { + if (this.Get == null) return null; + return new FieldSelection(this.Settings, this.Get._fields); + } + } + + [JsonObject] + public class GetFromUpdate + { + [JsonProperty(PropertyName = "found")] + public bool Found { get; set; } + + [JsonProperty(PropertyName = "_source")] + internal IDocument Source { get; set; } + + + [JsonProperty(PropertyName = "fields")] + internal IDictionary _fields { get; set; } + + } } diff --git a/src/Tests/Nest.Tests.Integration/Core/UpdateTests.cs b/src/Tests/Nest.Tests.Integration/Core/UpdateTests.cs index 977ba52485c..9d492d18d71 100644 --- a/src/Tests/Nest.Tests.Integration/Core/UpdateTests.cs +++ b/src/Tests/Nest.Tests.Integration/Core/UpdateTests.cs @@ -16,17 +16,27 @@ public void TestUpdate() Assert.NotNull(project); Assert.Greater(project.LOC, 0); var loc = project.LOC; - this.Client.Update(u => u - .IdFrom(project) - .Script("ctx._source.loc += 10") - .RetryOnConflict(5) - .Refresh() + var update = this.Client.Update(u => u + .IdFrom(project) + .Script("ctx._source.loc += 10") + .Fields("_source", "loc") + .RetryOnConflict(5) + .Refresh() ); project = this.Client.Source(s => s.Id(1)); Assert.AreEqual(project.LOC, loc + 10); Assert.AreNotEqual(project.Version, "1"); + + update.Get.Should().NotBeNull(); + update.Get.Found.Should().BeTrue(); + update.Source().Should().NotBeNull(); + update.Source().LOC.Should().Be(loc + 10); + var fieldLoc = update.Fields().FieldValues(p => p.LOC); + fieldLoc.Should().HaveCount(1); + fieldLoc.First().Should().Be(loc + 10); + } - + [Test] public void TestUpdate_ObjectInitializer() { @@ -49,7 +59,7 @@ public void TestUpdate_ObjectInitializer() public class ElasticsearchProjectLocUpdate { public int Id { get; set; } - [ElasticProperty(Name="loc",AddSortField=true)] + [ElasticProperty(Name = "loc", AddSortField = true)] public int LOC { get; set; } }