Skip to content

Commit

Permalink
Merge pull request #1588 from robertlyson/DetectNoop
Browse files Browse the repository at this point in the history
Support detect_noop in NEST #1587
  • Loading branch information
gmarz committed Oct 8, 2015
2 parents 15dac0e + 4cbae98 commit 7069ee5
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 5 deletions.
Expand Up @@ -28,6 +28,10 @@
"options": ["one", "quorum", "all"],
"description": "Explicit write consistency setting for the operation"
},
"detect_noop": {
"type": "boolean",
"description": "Specifying as true will cause Elasticsearch to check if there are changes and, if there aren’t, turn the update request into a noop."
},
"fields": {
"type": "list",
"description": "A comma-separated list of fields to return in the response"
Expand Down
Expand Up @@ -8531,6 +8531,16 @@ public UpdateRequestParameters Consistency(Consistency consistency)
}


internal bool _detect_noop { get; set; }
///<summary>Specifying as true will cause Elasticsearch to check if there are changes and, if there aren’t, turn the update request into a noop.</summary>
public UpdateRequestParameters DetectNoop(bool detect_noop)
{
this._detect_noop = detect_noop;
this.AddQueryString("detect_noop", this._detect_noop);
return this;
}


internal string _lang { get; set; }
///<summary>The script language (default: groovy)</summary>
public UpdateRequestParameters Lang(string lang)
Expand Down
10 changes: 7 additions & 3 deletions src/Nest/DSL/UpdateDescriptor.cs
Expand Up @@ -36,6 +36,9 @@ public interface IUpdateRequest<TDocument,TPartialDocument> : IDocumentOptionalP

[JsonProperty(PropertyName = "doc")]
TPartialDocument Doc { get; set; }

[JsonProperty(PropertyName = "detect_noop")]
bool? DetectNoop { get; set; }
}

internal static class UpdateRequestPathInfo
Expand Down Expand Up @@ -99,6 +102,7 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
public TDocument Upsert { get; set; }
public bool? DocAsUpsert { get; set; }
public TPartialDocument Doc { get; set; }
bool? IUpdateRequest<TDocument, TPartialDocument>.DetectNoop { get; set; }
}

public partial class UpdateDescriptor<TDocument,TPartialDocument>
Expand Down Expand Up @@ -126,7 +130,8 @@ public partial class UpdateDescriptor<TDocument,TPartialDocument>

TPartialDocument IUpdateRequest<TDocument, TPartialDocument>.Doc { get; set; }


bool? IUpdateRequest<TDocument, TPartialDocument>.DetectNoop { get; set; }

public UpdateDescriptor<TDocument, TPartialDocument> Script(string script)
{
script.ThrowIfNull("script");
Expand Down Expand Up @@ -194,7 +199,6 @@ public partial class UpdateDescriptor<TDocument,TPartialDocument>
this.Request.RequestParameters.AddQueryString("fields", fields);
return this;
}


///<summary>A comma-separated list of fields to return in the response</summary>
public UpdateDescriptor<TDocument,TPartialDocument> Fields(params Expression<Func<TPartialDocument, object>>[] typedPathLookups)
Expand All @@ -205,7 +209,7 @@ public partial class UpdateDescriptor<TDocument,TPartialDocument>
this.Request.RequestParameters.AddQueryString("fields",typedPathLookups.Select(e => (PropertyPathMarker)e).ToList());
return this;
}

protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<UpdateRequestParameters> pathInfo)
{
UpdateRequestPathInfo.Update(settings, pathInfo, this);
Expand Down
8 changes: 8 additions & 0 deletions src/Nest/DSL/_Descriptors.generated.cs
Expand Up @@ -7653,6 +7653,14 @@ public partial class UpdateDescriptor<TDocument,TPartialDocument>
}


///<summary>Specifying as true will cause Elasticsearch to check if there are changes and, if there aren’t, turn the update request into a noop.</summary>
public UpdateDescriptor<TDocument,TPartialDocument> DetectNoop(bool detect_noop = true)
{
this.Request.RequestParameters.DetectNoop(detect_noop);
return this;
}


///<summary>The script language (default: groovy)</summary>
public UpdateDescriptor<TDocument,TPartialDocument> Lang(string lang)
{
Expand Down
8 changes: 8 additions & 0 deletions src/Nest/DSL/_Requests.generated.cs
Expand Up @@ -7064,6 +7064,14 @@ public Consistency Consistency
}


///<summary>Specifying as true will cause Elasticsearch to check if there are changes and, if there aren’t, turn the update request into a noop.</summary>
public bool DetectNoop
{
get { return this.Request.RequestParameters.GetQueryStringValue<bool>("detect_noop"); }
set { this.Request.RequestParameters.AddQueryString("detect_noop", value); }
}


///<summary>The script language (default: groovy)</summary>
public string Lang
{
Expand Down
2 changes: 2 additions & 0 deletions src/Tests/Nest.Tests.Integration/Core/UpdateTests.cs
Expand Up @@ -21,8 +21,10 @@ public void TestUpdate()
.Script("ctx._source.loc += 10")
.Fields("_source", "loc")
.RetryOnConflict(5)
.DetectNoop()
.Refresh()
);
update.IsValid.Should().BeTrue();
project = this.Client.Source<ElasticsearchProject>(s => s.Id(1));
Assert.AreEqual(project.LOC, loc + 10);
Assert.AreNotEqual(project.Version, "1");
Expand Down
10 changes: 10 additions & 0 deletions src/Tests/Nest.Tests.Unit/Core/Update/UpdateDetectNoop.json
@@ -0,0 +1,10 @@
{
"script": "ctx._source.counter += count",
"params": {
"count": 4
},
"upsert": {
"count": 1
},
"detect_noop": true
}
4 changes: 2 additions & 2 deletions src/Tests/Nest.Tests.Unit/Core/Update/UpdateTests.cs
@@ -1,4 +1,5 @@
using System.Reflection;
using Elasticsearch.Net;
using NUnit.Framework;
using Nest.Tests.MockData.Domain;
using Newtonsoft.Json;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void UpsertUsingScript()
.Add("count", 4)
)
.Upsert(new UpsertCount { Count = 1 });
this.JsonEquals(s, MethodBase.GetCurrentMethod());
this.JsonEquals(s, MethodBase.GetCurrentMethod());
}

[Test]
Expand Down Expand Up @@ -79,6 +80,5 @@ public void UpdateUsingPartialWithNull()

this.JsonEquals(s, MethodBase.GetCurrentMethod());
}

}
}
6 changes: 6 additions & 0 deletions src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj
Expand Up @@ -410,6 +410,9 @@
<Compile Include="QueryParsers\Visitor\DslPrettyPrintVisitor.cs" />
<Compile Include="QueryParsers\Visitor\VisitorDemoUseCase.cs" />
<Compile Include="QueryParsers\Visitor\VisitorTests.cs" />
<None Include="Core\Update\UpdateDetectNoop.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Reproduce\Issue1528_ExplicitTypeAndIndex.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -1589,4 +1592,7 @@
<Paket>True</Paket>
</Reference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
</Project>

0 comments on commit 7069ee5

Please sign in to comment.