5
5
6
6
namespace Nest
7
7
{
8
- public interface IBulkUpdateOperation < TDocument , TPartialUpdate > : IBulkOperation
8
+ public interface IBulkUpdateOperation < TDocument , TPartialDocument > : IBulkOperation
9
9
where TDocument : class
10
- where TPartialUpdate : class
10
+ where TPartialDocument : class
11
11
{
12
- TDocument Document { get ; set ; }
12
+ TDocument InferFrom { get ; set ; }
13
+
13
14
TDocument Upsert { get ; set ; }
14
15
15
- TPartialUpdate PartialUpdate { get ; set ; }
16
+ TPartialDocument Doc { get ; set ; }
16
17
17
18
bool ? DocAsUpsert { get ; set ; }
18
19
@@ -23,18 +24,39 @@ public interface IBulkUpdateOperation<TDocument, TPartialUpdate> : IBulkOperatio
23
24
Dictionary < string , object > Params { get ; set ; }
24
25
}
25
26
26
- public class BulkUpdateOperation < TDocument , TPartialUpdate >
27
- : BulkOperationBase , IBulkUpdateOperation < TDocument , TPartialUpdate >
27
+ public class BulkUpdateOperation < TDocument , TPartialDocument > : BulkOperationBase , IBulkUpdateOperation < TDocument , TPartialDocument >
28
28
where TDocument : class
29
- where TPartialUpdate : class
29
+ where TPartialDocument : class
30
30
{
31
+
31
32
33
+ public BulkUpdateOperation ( string id ) { this . Id = id ; }
34
+ public BulkUpdateOperation ( long id ) : this ( id . ToString ( CultureInfo . InvariantCulture ) ) { }
32
35
33
- public BulkUpdateOperation ( ) { }
34
- public BulkUpdateOperation ( TDocument document , TPartialUpdate update ) : this ( )
36
+ /// <summary>
37
+ /// Create a new bulk operation
38
+ /// </summary>
39
+ /// <param name="idFrom">Use this document to infer the id from</param>
40
+ /// <param name="useIdFromAsUpsert">Use the document to infer on as the upsert document in this update operation</param>
41
+ public BulkUpdateOperation ( TDocument idFrom , bool useIdFromAsUpsert = false )
35
42
{
36
- this . PartialUpdate = update ;
37
- this . Document = document ;
43
+ this . InferFrom = idFrom ;
44
+ if ( useIdFromAsUpsert )
45
+ this . Upsert = idFrom ;
46
+ }
47
+
48
+ /// <summary>
49
+ /// Create a new Bulk Operation
50
+ /// </summary>
51
+ /// <param name="idFrom">Use this document to infer the id from</param>
52
+ /// <param name="update">The partial update document (doc) to send as update</param>
53
+ /// <param name="useIdFromAsUpsert">Use the document to infer on as the upsert document in this update operation</param>
54
+ public BulkUpdateOperation ( TDocument idFrom , TPartialDocument update , bool useIdFromAsUpsert = false )
55
+ {
56
+ this . InferFrom = idFrom ;
57
+ if ( useIdFromAsUpsert )
58
+ this . Upsert = idFrom ;
59
+ this . Doc = update ;
38
60
}
39
61
40
62
@@ -44,14 +66,14 @@ public BulkUpdateOperation(TDocument document, TPartialUpdate update) : this()
44
66
45
67
public override string GetIdForOperation ( ElasticInferrer inferrer )
46
68
{
47
- return this . Id ?? inferrer . Id ( this . Document ) ;
69
+ return this . Id ?? inferrer . Id ( this . InferFrom ) ;
48
70
}
49
71
50
72
public override object GetBody ( )
51
73
{
52
- return new BulkUpdateBody < TDocument , TPartialUpdate >
74
+ return new BulkUpdateBody < TDocument , TPartialDocument >
53
75
{
54
- _PartialUpdate = this . PartialUpdate ,
76
+ _PartialUpdate = this . Doc ,
55
77
_Script = this . Script ,
56
78
_Lang = this . Lang ,
57
79
_Params = this . Params ,
@@ -60,38 +82,43 @@ public override object GetBody()
60
82
} ;
61
83
}
62
84
63
- public TDocument Document { get ; set ; }
85
+ public TDocument InferFrom { get ; set ; }
64
86
public TDocument Upsert { get ; set ; }
65
- public TPartialUpdate PartialUpdate { get ; set ; }
87
+ public TPartialDocument Doc { get ; set ; }
66
88
public bool ? DocAsUpsert { get ; set ; }
67
89
public string Lang { get ; set ; }
68
90
public string Script { get ; set ; }
69
91
public Dictionary < string , object > Params { get ; set ; }
70
92
}
71
93
72
- public class BulkUpdateDescriptor < TDocument , TPartialUpdate >
73
- : BulkOperationDescriptorBase , IBulkUpdateOperation < TDocument , TPartialUpdate >
94
+ public class BulkUpdateDescriptor < TDocument , TPartialDocument > : BulkOperationDescriptorBase , IBulkUpdateOperation < TDocument , TPartialDocument >
74
95
where TDocument : class
75
- where TPartialUpdate : class
96
+ where TPartialDocument : class
76
97
{
77
- private IBulkUpdateOperation < TDocument , TPartialUpdate > Self { get { return this ; } }
98
+ private IBulkUpdateOperation < TDocument , TPartialDocument > Self { get { return this ; } }
78
99
79
100
protected override string BulkOperationType { get { return "update" ; } }
80
101
protected override Type BulkOperationClrType { get { return typeof ( TDocument ) ; } }
81
102
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 ; }
103
+ TDocument IBulkUpdateOperation < TDocument , TPartialDocument > . InferFrom { get ; set ; }
104
+
105
+ TDocument IBulkUpdateOperation < TDocument , TPartialDocument > . Upsert { get ; set ; }
106
+
107
+ TPartialDocument IBulkUpdateOperation < TDocument , TPartialDocument > . Doc { get ; set ; }
108
+
109
+ bool ? IBulkUpdateOperation < TDocument , TPartialDocument > . DocAsUpsert { get ; set ; }
110
+
111
+ string IBulkUpdateOperation < TDocument , TPartialDocument > . Lang { get ; set ; }
112
+
113
+ string IBulkUpdateOperation < TDocument , TPartialDocument > . Script { get ; set ; }
114
+
115
+ Dictionary < string , object > IBulkUpdateOperation < TDocument , TPartialDocument > . Params { get ; set ; }
89
116
90
117
protected override object GetBulkOperationBody ( )
91
118
{
92
- return new BulkUpdateBody < TDocument , TPartialUpdate >
119
+ return new BulkUpdateBody < TDocument , TPartialDocument >
93
120
{
94
- _PartialUpdate = Self . PartialUpdate ,
121
+ _PartialUpdate = Self . Doc ,
95
122
_Script = Self . Script ,
96
123
_Lang = Self . Lang ,
97
124
_Params = Self . Params ,
@@ -102,13 +129,13 @@ protected override object GetBulkOperationBody()
102
129
103
130
protected override string GetIdForOperation ( ElasticInferrer inferrer )
104
131
{
105
- return Self . Id ?? inferrer . Id ( Self . Document ) ;
132
+ return Self . Id ?? inferrer . Id ( Self . InferFrom ) ?? inferrer . Id ( Self . Upsert ) ;
106
133
}
107
134
108
135
/// <summary>
109
136
/// Manually set the index, default to the default index or the fixed index set on the bulk operation
110
137
/// </summary>
111
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Index ( string index )
138
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Index ( string index )
112
139
{
113
140
index . ThrowIfNullOrEmpty ( "indices" ) ;
114
141
Self . Index = index ;
@@ -118,7 +145,7 @@ public BulkUpdateDescriptor<TDocument, TPartialUpdate> Index(string index)
118
145
/// Manualy set the type to get the object from, default to whatever
119
146
/// T will be inferred to if not passed or the fixed type set on the parent bulk operation
120
147
/// </summary>
121
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Type ( string type )
148
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Type ( string type )
122
149
{
123
150
type . ThrowIfNullOrEmpty ( "type" ) ;
124
151
Self . Type = type ;
@@ -128,7 +155,7 @@ public BulkUpdateDescriptor<TDocument, TPartialUpdate> Type(string type)
128
155
/// <summary>
129
156
/// Manually set the type of which a typename will be inferred
130
157
/// </summary>
131
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Type ( Type type )
158
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Type ( Type type )
132
159
{
133
160
type . ThrowIfNull ( "type" ) ;
134
161
Self . Type = type ;
@@ -138,15 +165,15 @@ public BulkUpdateDescriptor<TDocument, TPartialUpdate> Type(Type type)
138
165
/// <summary>
139
166
/// Manually set the id for the newly created object
140
167
/// </summary>
141
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Id ( long id )
168
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Id ( long id )
142
169
{
143
170
return this . Id ( id . ToString ( CultureInfo . InvariantCulture ) ) ;
144
171
}
145
172
146
173
/// <summary>
147
174
/// Manually set the id for the newly created object
148
175
/// </summary>
149
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Id ( string id )
176
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Id ( string id )
150
177
{
151
178
Self . Id = id ;
152
179
return this ;
@@ -156,91 +183,92 @@ public BulkUpdateDescriptor<TDocument, TPartialUpdate> Id(string id)
156
183
/// The object to update, if id is not manually set it will be inferred from the object.
157
184
/// Used ONLY to infer the ID see Document() to apply a partial object merge.
158
185
/// </summary>
159
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Document ( TDocument @object )
186
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > IdFrom ( TDocument @object , bool useAsUpsert = false )
160
187
{
161
- Self . Document = @object ;
188
+ Self . InferFrom = @object ;
189
+ if ( useAsUpsert ) return this . Upsert ( @object ) ;
162
190
return this ;
163
191
}
164
192
/// <summary>
165
193
/// A document to upsert when the specified document to be updated is not found
166
194
/// </summary>
167
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Upsert ( TDocument @object )
195
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Upsert ( TDocument @object )
168
196
{
169
197
Self . Upsert = @object ;
170
198
return this ;
171
199
}
172
200
/// <summary>
173
201
/// The partial update document to be merged on to the existing object.
174
202
/// </summary>
175
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > PartialUpdate ( TPartialUpdate @object )
203
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Doc ( TPartialDocument @object )
176
204
{
177
- Self . PartialUpdate = @object ;
205
+ Self . Doc = @object ;
178
206
return this ;
179
207
}
180
208
181
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > DocAsUpsert ( bool docAsUpsert = true )
209
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > DocAsUpsert ( bool partialDocumentAsUpsert = true )
182
210
{
183
- Self . DocAsUpsert = docAsUpsert ;
211
+ Self . DocAsUpsert = partialDocumentAsUpsert ;
184
212
return this ;
185
213
}
186
214
187
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Lang ( string lang )
215
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Lang ( string lang )
188
216
{
189
217
Self . Lang = lang ;
190
218
return this ;
191
219
}
192
220
193
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Script ( string script )
221
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Script ( string script )
194
222
{
195
223
script . ThrowIfNull ( "script" ) ;
196
224
Self . Script = script ;
197
225
return this ;
198
226
}
199
227
200
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Params ( Func < FluentDictionary < string , object > , FluentDictionary < string , object > > paramDictionary )
228
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Params ( Func < FluentDictionary < string , object > , FluentDictionary < string , object > > paramDictionary )
201
229
{
202
230
paramDictionary . ThrowIfNull ( "paramDictionary" ) ;
203
231
Self . Params = paramDictionary ( new FluentDictionary < string , object > ( ) ) ;
204
232
return this ;
205
233
}
206
234
207
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Version ( string version )
235
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Version ( string version )
208
236
{
209
237
Self . Version = version ;
210
238
return this ;
211
239
}
212
240
213
241
214
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > VersionType ( VersionType versionType )
242
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > VersionType ( VersionType versionType )
215
243
{
216
244
Self . VersionType = versionType ;
217
245
return this ;
218
246
}
219
247
220
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Routing ( string routing )
248
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Routing ( string routing )
221
249
{
222
250
Self . Routing = routing ;
223
251
return this ;
224
252
}
225
253
226
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Parent ( string parent ) {
254
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Parent ( string parent ) {
227
255
Self . Parent = parent ;
228
256
return this ;
229
257
}
230
258
231
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Timestamp ( long timestamp )
259
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Timestamp ( long timestamp )
232
260
{
233
261
Self . Timestamp = timestamp ;
234
262
return this ;
235
263
}
236
264
237
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > Ttl ( string ttl )
265
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > Ttl ( string ttl )
238
266
{
239
267
Self . Ttl = ttl ;
240
268
return this ;
241
269
}
242
270
243
- public BulkUpdateDescriptor < TDocument , TPartialUpdate > RetriesOnConflict ( int retriesOnConflict )
271
+ public BulkUpdateDescriptor < TDocument , TPartialDocument > RetriesOnConflict ( int retriesOnConflict )
244
272
{
245
273
Self . RetriesOnConflict = retriesOnConflict ;
246
274
return this ;
0 commit comments