Skip to content

Commit 8ecab64

Browse files
committed
Fix #2665 add support for scripted_upsert
1 parent 2c9e694 commit 8ecab64

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/Elasticsearch.Net/Connection/HttpConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected virtual HttpWebRequest CreateWebRequest(RequestData requestData)
6363
request.ReadWriteTimeout = timeout;
6464

6565
//WebRequest won't send Content-Length: 0 for empty bodies
66-
//which goes against RFC's and might break i.e IIS when used as a proxy.
66+
//which goes against RFC's and might break i.e IIS hen used as a proxy.
6767
//see: https://github.com/elasticsearch/elasticsearch-net/issues/562
6868
var m = requestData.Method.GetStringValue();
6969
request.Method = m;

src/Nest/Document/Multiple/Bulk/BulkOperation/BulkUpdate.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public interface IBulkUpdateOperation<TDocument, TPartialDocument> : IBulkOperat
3131
/// </summary>
3232
bool? DocAsUpsert { get; set; }
3333

34+
/// <summary>
35+
/// If you would like your script to run regardless of whether the document exists or not — i.e. the script handles
36+
/// initializing the document instead of the upsert element — then set scripted_upsert to true
37+
/// </summary>
38+
bool? ScriptedUpsert { get; set; }
39+
3440
/// <summary>
3541
/// A script to specify the update.
3642
/// </summary>
@@ -109,6 +115,12 @@ protected override object GetBody() =>
109115
/// </summary>
110116
public bool? DocAsUpsert { get; set; }
111117

118+
/// <summary>
119+
/// If you would like your script to run regardless of whether the document exists or not — i.e. the script handles
120+
/// initializing the document instead of the upsert element — then set scripted_upsert to true
121+
/// </summary>
122+
public bool? ScriptedUpsert { get; set; }
123+
112124
/// <summary>
113125
/// A script to specify the update.
114126
/// </summary>
@@ -128,6 +140,7 @@ public class BulkUpdateDescriptor<TDocument, TPartialDocument>
128140
TDocument IBulkUpdateOperation<TDocument, TPartialDocument>.Upsert { get; set; }
129141
TPartialDocument IBulkUpdateOperation<TDocument, TPartialDocument>.Doc { get; set; }
130142
bool? IBulkUpdateOperation<TDocument, TPartialDocument>.DocAsUpsert { get; set; }
143+
bool? IBulkUpdateOperation<TDocument, TPartialDocument>.ScriptedUpsert { get; set; }
131144
IScript IBulkUpdateOperation<TDocument, TPartialDocument>.Script { get; set; }
132145

133146
protected override object GetBulkOperationBody() =>
@@ -136,7 +149,8 @@ protected override object GetBulkOperationBody() =>
136149
_PartialUpdate = Self.Doc,
137150
_Script = Self.Script,
138151
_Upsert = Self.Upsert,
139-
_DocAsUpsert = Self.DocAsUpsert
152+
_DocAsUpsert = Self.DocAsUpsert,
153+
_ScriptedUpsert = Self.ScriptedUpsert
140154
};
141155

142156
protected override Id GetIdForOperation(Inferrer inferrer) =>
@@ -171,6 +185,13 @@ public BulkUpdateDescriptor<TDocument, TPartialDocument> DocAsUpsert(bool partia
171185
Assign(a => a.DocAsUpsert = partialDocumentAsUpsert);
172186

173187
/// <summary>
188+
/// If you would like your script to run regardless of whether the document exists or not — i.e. the script handles
189+
/// initializing the document instead of the upsert element — then set scripted_upsert to true
190+
/// </summary>
191+
/// <summary>
192+
public BulkUpdateDescriptor<TDocument, TPartialDocument> ScriptedUpsert(bool scriptedUpsert = true) =>
193+
Assign(a => a.ScriptedUpsert = scriptedUpsert);
194+
174195
/// A script to specify the update.
175196
/// </summary>
176197
public BulkUpdateDescriptor<TDocument, TPartialDocument> Script(Func<ScriptDescriptor, IScript> scriptSelector) =>

src/Nest/Document/Multiple/Bulk/BulkOperation/BulkUpdateBody.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ internal class BulkUpdateBody<TDocument, TPartialUpdate>
1818

1919
[JsonProperty("script")]
2020
internal IScript _Script { get; set; }
21+
22+
[JsonProperty("scripted_upsert")]
23+
internal bool? _ScriptedUpsert { get; set; }
2124
}
2225
}

0 commit comments

Comments
 (0)