Skip to content

Commit ac3ee8e

Browse files
authored
fix #2764 (#2782)
1 parent 2e7022f commit ac3ee8e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Nest/Document/Single/Update/UpdateRequest.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ public partial interface IUpdateRequest<TDocument, TPartialDocument>
1818
[JsonProperty(PropertyName = "doc_as_upsert")]
1919
bool? DocAsUpsert { get; set; }
2020

21+
/// <summary>
22+
/// If you would like your script to run regardless of whether the document exists or not — i.e. the script handles
23+
/// initializing the document instead of the upsert element — then set scripted_upsert to true
24+
/// </summary>
25+
[JsonProperty(PropertyName = "scripted_upsert")]
26+
bool? ScriptedUpsert { get; set; }
27+
2128
[JsonProperty(PropertyName = "doc")]
2229
TPartialDocument Doc { get; set; }
2330

@@ -29,12 +36,20 @@ public partial class UpdateRequest<TDocument, TPartialDocument>
2936
where TDocument : class
3037
where TPartialDocument : class
3138
{
39+
/// <inheritdoc/>
3240
public IScript Script { get; set; }
41+
/// <inheritdoc/>
3342
public TDocument Upsert { get; set; }
43+
/// <inheritdoc/>
3444
public bool? DocAsUpsert { get; set; }
45+
/// <inheritdoc/>
3546
public TPartialDocument Doc { get; set; }
47+
/// <inheritdoc/>
3648
public bool? DetectNoop { get; set; }
49+
/// <inheritdoc/>
50+
public bool? ScriptedUpsert { get; set; }
3751

52+
/// <inheritdoc/>
3853
public Fields Fields
3954
{
4055
get { return Self.RequestParameters.GetQueryStringValue<Fields>("fields"); }
@@ -56,6 +71,8 @@ public partial class UpdateDescriptor<TDocument, TPartialDocument>
5671

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

74+
bool? IUpdateRequest<TDocument, TPartialDocument>.ScriptedUpsert { get; set; }
75+
5976
/// <summary>
6077
/// The full document to be created if an existing document does not exist for a partial merge.
6178
/// </summary>
@@ -70,6 +87,8 @@ public partial class UpdateDescriptor<TDocument, TPartialDocument>
7087

7188
public UpdateDescriptor<TDocument, TPartialDocument> DetectNoop(bool detectNoop = true) => Assign(a => a.DetectNoop = detectNoop);
7289

90+
public UpdateDescriptor<TDocument, TPartialDocument> ScriptedUpsert(bool scriptedUpsert = true) => Assign(a => a.ScriptedUpsert = scriptedUpsert);
91+
7392
public UpdateDescriptor<TDocument, TPartialDocument> Script(Func<ScriptDescriptor, IScript> scriptSelector) =>
7493
Assign(a => a.Script = scriptSelector?.Invoke(new ScriptDescriptor()));
7594

src/Tests/Document/Single/Update/UpdateWithScriptApiTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ protected override LazyResponses ClientUsage() => Calls(
4040

4141
protected override object ExpectJson { get; } = new
4242
{
43+
scripted_upsert = true,
4344
script = new
4445
{
4546
inline = "ctx._source.name = \"params.name\"",
@@ -53,7 +54,8 @@ protected override LazyResponses ClientUsage() => Calls(
5354
protected override UpdateDescriptor<Project, Project> NewDescriptor() => new UpdateDescriptor<Project, Project>(DocumentPath<Project>.Id(CallIsolatedValue));
5455

5556
protected override Func<UpdateDescriptor<Project, Project>, IUpdateRequest<Project, Project>> Fluent => d => d
56-
.Script(s => s
57+
.ScriptedUpsert()
58+
.Script(s => s
5759
.Inline("ctx._source.name = \"params.name\"")
5860
.Lang("painless")
5961
.Params(p => p
@@ -63,6 +65,7 @@ protected override LazyResponses ClientUsage() => Calls(
6365

6466
protected override UpdateRequest<Project, Project> Initializer => new UpdateRequest<Project, Project>(CallIsolatedValue)
6567
{
68+
ScriptedUpsert = true,
6669
Script = new InlineScript("ctx._source.name = \"params.name\"")
6770
{
6871
Lang = "painless",

0 commit comments

Comments
 (0)