55
66namespace Nest
77{
8- public interface IBulkUpdateOperation < TDocument , TPartialUpdate > : IBulkOperation
8+ public interface IBulkUpdateOperation < TDocument , TPartialDocument > : IBulkOperation
99 where TDocument : class
10- where TPartialUpdate : class
10+ where TPartialDocument : class
1111 {
12- TDocument Document { get ; set ; }
12+ TDocument InferFrom { get ; set ; }
13+
1314 TDocument Upsert { get ; set ; }
1415
15- TPartialUpdate PartialUpdate { get ; set ; }
16+ TPartialDocument PartialDocument { get ; set ; }
1617
17- bool ? DocAsUpsert { get ; set ; }
18+ bool ? PartialDocumentAsUpsert { get ; set ; }
1819
1920 string Lang { get ; set ; }
2021
@@ -23,18 +24,19 @@ public interface IBulkUpdateOperation<TDocument, TPartialUpdate> : IBulkOperatio
2324 Dictionary < string , object > Params { get ; set ; }
2425 }
2526
26- public class BulkUpdateOperation < TDocument , TPartialUpdate >
27- : BulkOperationBase , IBulkUpdateOperation < TDocument , TPartialUpdate >
27+ public class BulkUpdateOperation < TDocument , TPartialDocument > : BulkOperationBase , IBulkUpdateOperation < TDocument , TPartialDocument >
2828 where TDocument : class
29- where TPartialUpdate : class
29+ where TPartialDocument : class
3030 {
31-
32-
33- public BulkUpdateOperation ( ) { }
34- public BulkUpdateOperation ( TDocument document , TPartialUpdate update ) : this ( )
31+
32+ public BulkUpdateOperation ( TDocument inferFrom )
33+ {
34+ this . InferFrom = inferFrom ;
35+ }
36+ public BulkUpdateOperation ( TDocument inferFrom , TPartialDocument update )
3537 {
36- this . PartialUpdate = update ;
37- this . Document = document ;
38+ this . InferFrom = inferFrom ;
39+ this . PartialDocument = update ;
3840 }
3941
4042
@@ -44,71 +46,76 @@ public BulkUpdateOperation(TDocument document, TPartialUpdate update) : this()
4446
4547 public override string GetIdForOperation ( ElasticInferrer inferrer )
4648 {
47- return this . Id ?? inferrer . Id ( this . Document ) ;
49+ return this . Id ?? inferrer . Id ( this . InferFrom ) ;
4850 }
4951
5052 public override object GetBody ( )
5153 {
52- return new BulkUpdateBody < TDocument , TPartialUpdate >
54+ return new BulkUpdateBody < TDocument , TPartialDocument >
5355 {
54- _PartialUpdate = this . PartialUpdate ,
56+ _PartialUpdate = this . PartialDocument ,
5557 _Script = this . Script ,
5658 _Lang = this . Lang ,
5759 _Params = this . Params ,
5860 _Upsert = this . Upsert ,
59- _DocAsUpsert = this . DocAsUpsert
61+ _DocAsUpsert = this . PartialDocumentAsUpsert
6062 } ;
6163 }
6264
63- public TDocument Document { get ; set ; }
65+ public TDocument InferFrom { get ; set ; }
6466 public TDocument Upsert { get ; set ; }
65- public TPartialUpdate PartialUpdate { get ; set ; }
66- public bool ? DocAsUpsert { get ; set ; }
67+ public TPartialDocument PartialDocument { get ; set ; }
68+ public bool ? PartialDocumentAsUpsert { get ; set ; }
6769 public string Lang { get ; set ; }
6870 public string Script { get ; set ; }
6971 public Dictionary < string , object > Params { get ; set ; }
7072 }
7173
72- public class BulkUpdateDescriptor < TDocument , TPartialUpdate >
73- : BulkOperationDescriptorBase , IBulkUpdateOperation < TDocument , TPartialUpdate >
74+ public class BulkUpdateDescriptor < TDocument , TPartialDocument > : BulkOperationDescriptorBase , IBulkUpdateOperation < TDocument , TPartialDocument >
7475 where TDocument : class
75- where TPartialUpdate : class
76+ where TPartialDocument : class
7677 {
77- private IBulkUpdateOperation < TDocument , TPartialUpdate > Self { get { return this ; } }
78+ private IBulkUpdateOperation < TDocument , TPartialDocument > Self { get { return this ; } }
7879
7980 protected override string BulkOperationType { get { return "update" ; } }
8081 protected override Type BulkOperationClrType { get { return typeof ( TDocument ) ; } }
8182
82- TDocument IBulkUpdateOperation < TDocument , TPartialUpdate > . Document { get ; set ; }
83- TDocument IBulkUpdateOperation < TDocument , TPartialUpdate > . Upsert { get ; set ; }
84- TPartialUpdate IBulkUpdateOperation < TDocument , TPartialUpdate > . PartialUpdate { get ; set ; }
85- bool ? IBulkUpdateOperation < TDocument , TPartialUpdate > . DocAsUpsert { get ; set ; }
86- string IBulkUpdateOperation < TDocument , TPartialUpdate > . Lang { get ; set ; }
87- string IBulkUpdateOperation < TDocument , TPartialUpdate > . Script { get ; set ; }
88- Dictionary < string , object > IBulkUpdateOperation < TDocument , TPartialUpdate > . Params { get ; set ; }
83+ TDocument IBulkUpdateOperation < TDocument , TPartialDocument > . InferFrom { get ; set ; }
84+
85+ TDocument IBulkUpdateOperation < TDocument , TPartialDocument > . Upsert { get ; set ; }
86+
87+ TPartialDocument IBulkUpdateOperation < TDocument , TPartialDocument > . PartialDocument { get ; set ; }
88+
89+ bool ? IBulkUpdateOperation < TDocument , TPartialDocument > . PartialDocumentAsUpsert { get ; set ; }
90+
91+ string IBulkUpdateOperation < TDocument , TPartialDocument > . Lang { get ; set ; }
92+
93+ string IBulkUpdateOperation < TDocument , TPartialDocument > . Script { get ; set ; }
94+
95+ Dictionary < string , object > IBulkUpdateOperation < TDocument , TPartialDocument > . Params { get ; set ; }
8996
9097 protected override object GetBulkOperationBody ( )
9198 {
92- return new BulkUpdateBody < TDocument , TPartialUpdate >
99+ return new BulkUpdateBody < TDocument , TPartialDocument >
93100 {
94- _PartialUpdate = Self . PartialUpdate ,
101+ _PartialUpdate = Self . PartialDocument ,
95102 _Script = Self . Script ,
96103 _Lang = Self . Lang ,
97104 _Params = Self . Params ,
98105 _Upsert = Self . Upsert ,
99- _DocAsUpsert = Self . DocAsUpsert
106+ _DocAsUpsert = Self . PartialDocumentAsUpsert
100107 } ;
101108 }
102109
103110 protected override string GetIdForOperation ( ElasticInferrer inferrer )
104111 {
105- return Self . Id ?? inferrer . Id ( Self . Document ) ;
112+ return Self . Id ?? inferrer . Id ( Self . InferFrom ) ?? inferrer . Id ( Self . Upsert ) ;
106113 }
107114
108115 /// <summary>
109116 /// Manually set the index, default to the default index or the fixed index set on the bulk operation
110117 /// </summary>
111- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Index ( string index )
118+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Index ( string index )
112119 {
113120 index . ThrowIfNullOrEmpty ( "indices" ) ;
114121 Self . Index = index ;
@@ -118,7 +125,7 @@ public BulkUpdateDescriptor<TDocument, TPartialUpdate> Index(string index)
118125 /// Manualy set the type to get the object from, default to whatever
119126 /// T will be inferred to if not passed or the fixed type set on the parent bulk operation
120127 /// </summary>
121- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Type ( string type )
128+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Type ( string type )
122129 {
123130 type . ThrowIfNullOrEmpty ( "type" ) ;
124131 Self . Type = type ;
@@ -128,7 +135,7 @@ public BulkUpdateDescriptor<TDocument, TPartialUpdate> Type(string type)
128135 /// <summary>
129136 /// Manually set the type of which a typename will be inferred
130137 /// </summary>
131- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Type ( Type type )
138+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Type ( Type type )
132139 {
133140 type . ThrowIfNull ( "type" ) ;
134141 Self . Type = type ;
@@ -138,15 +145,15 @@ public BulkUpdateDescriptor<TDocument, TPartialUpdate> Type(Type type)
138145 /// <summary>
139146 /// Manually set the id for the newly created object
140147 /// </summary>
141- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Id ( long id )
148+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Id ( long id )
142149 {
143150 return this . Id ( id . ToString ( CultureInfo . InvariantCulture ) ) ;
144151 }
145152
146153 /// <summary>
147154 /// Manually set the id for the newly created object
148155 /// </summary>
149- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Id ( string id )
156+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Id ( string id )
150157 {
151158 Self . Id = id ;
152159 return this ;
@@ -156,91 +163,92 @@ public BulkUpdateDescriptor<TDocument, TPartialUpdate> Id(string id)
156163 /// The object to update, if id is not manually set it will be inferred from the object.
157164 /// Used ONLY to infer the ID see Document() to apply a partial object merge.
158165 /// </summary>
159- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Document ( TDocument @object )
166+ public BulkUpdateDescriptor < TDocument , TPartialDocument > InferFrom ( TDocument @object , bool useAsUpsert = false )
160167 {
161- Self . Document = @object ;
168+ Self . InferFrom = @object ;
169+ if ( useAsUpsert ) return this . Upsert ( @object ) ;
162170 return this ;
163171 }
164172 /// <summary>
165173 /// A document to upsert when the specified document to be updated is not found
166174 /// </summary>
167- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Upsert ( TDocument @object )
175+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Upsert ( TDocument @object )
168176 {
169177 Self . Upsert = @object ;
170178 return this ;
171179 }
172180 /// <summary>
173181 /// The partial update document to be merged on to the existing object.
174182 /// </summary>
175- public BulkUpdateDescriptor < TDocument , TPartialUpdate > PartialUpdate ( TPartialUpdate @object )
183+ public BulkUpdateDescriptor < TDocument , TPartialDocument > PartialDocument ( TPartialDocument @object )
176184 {
177- Self . PartialUpdate = @object ;
185+ Self . PartialDocument = @object ;
178186 return this ;
179187 }
180188
181- public BulkUpdateDescriptor < TDocument , TPartialUpdate > DocAsUpsert ( bool docAsUpsert = true )
189+ public BulkUpdateDescriptor < TDocument , TPartialDocument > PartialDocumentAsUpsert ( bool partialDocumentAsUpsert = true )
182190 {
183- Self . DocAsUpsert = docAsUpsert ;
191+ Self . PartialDocumentAsUpsert = partialDocumentAsUpsert ;
184192 return this ;
185193 }
186194
187- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Lang ( string lang )
195+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Lang ( string lang )
188196 {
189197 Self . Lang = lang ;
190198 return this ;
191199 }
192200
193- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Script ( string script )
201+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Script ( string script )
194202 {
195203 script . ThrowIfNull ( "script" ) ;
196204 Self . Script = script ;
197205 return this ;
198206 }
199207
200- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Params ( Func < FluentDictionary < string , object > , FluentDictionary < string , object > > paramDictionary )
208+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Params ( Func < FluentDictionary < string , object > , FluentDictionary < string , object > > paramDictionary )
201209 {
202210 paramDictionary . ThrowIfNull ( "paramDictionary" ) ;
203211 Self . Params = paramDictionary ( new FluentDictionary < string , object > ( ) ) ;
204212 return this ;
205213 }
206214
207- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Version ( string version )
215+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Version ( string version )
208216 {
209217 Self . Version = version ;
210218 return this ;
211219 }
212220
213221
214- public BulkUpdateDescriptor < TDocument , TPartialUpdate > VersionType ( VersionType versionType )
222+ public BulkUpdateDescriptor < TDocument , TPartialDocument > VersionType ( VersionType versionType )
215223 {
216224 Self . VersionType = versionType ;
217225 return this ;
218226 }
219227
220- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Routing ( string routing )
228+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Routing ( string routing )
221229 {
222230 Self . Routing = routing ;
223231 return this ;
224232 }
225233
226- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Parent ( string parent ) {
234+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Parent ( string parent ) {
227235 Self . Parent = parent ;
228236 return this ;
229237 }
230238
231- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Timestamp ( long timestamp )
239+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Timestamp ( long timestamp )
232240 {
233241 Self . Timestamp = timestamp ;
234242 return this ;
235243 }
236244
237- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Ttl ( string ttl )
245+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Ttl ( string ttl )
238246 {
239247 Self . Ttl = ttl ;
240248 return this ;
241249 }
242250
243- public BulkUpdateDescriptor < TDocument , TPartialUpdate > RetriesOnConflict ( int retriesOnConflict )
251+ public BulkUpdateDescriptor < TDocument , TPartialDocument > RetriesOnConflict ( int retriesOnConflict )
244252 {
245253 Self . RetriesOnConflict = retriesOnConflict ;
246254 return this ;
0 commit comments