-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathBulkUpdateDescriptor.cs
210 lines (181 loc) · 5.15 KB
/
BulkUpdateDescriptor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
using System;
using System.Collections.Generic;
using System.Globalization;
using Nest.Resolvers;
using Elasticsearch.Net;
using Nest.Resolvers.Converters;
namespace Nest
{
public class BulkUpdateDescriptor<T, K> : BaseBulkOperation
where T : class
where K : class
{
internal override Type _ClrType { get { return typeof(T); } }
internal override string _Operation { get { return "update"; } }
internal override object _Object { get; set; }
internal string _Lang { get; set; }
internal K _Document { get; set; }
internal string _Script { get; set; }
internal Dictionary<string, object> _Params { get; set; }
internal object _Upsert { get; set; }
internal bool? _DocAsUpsert { get; set; }
internal override object GetBody()
{
return new BulkUpdateBody<T, K>
{
_Document = this._Document,
_Script = this._Script,
_Lang = this._Lang,
_Params = this._Params,
_Upsert = this._Upsert,
_DocAsUpsert = this._DocAsUpsert
};
}
internal override string GetIdForObject(ElasticInferrer inferrer)
{
if (!this._Id.IsNullOrEmpty())
return this._Id;
return inferrer.Id((T)_Object);
}
/// <summary>
/// Manually set the index, default to the default index or the fixed index set on the bulk operation
/// </summary>
public BulkUpdateDescriptor<T, K> Index(string index)
{
index.ThrowIfNullOrEmpty("indices");
this._Index = index;
return this;
}
/// <summary>
/// Manualy set the type to get the object from, default to whatever
/// T will be inferred to if not passed or the fixed type set on the parent bulk operation
/// </summary>
public BulkUpdateDescriptor<T, K> Type(string type)
{
type.ThrowIfNullOrEmpty("type");
this._Type = type;
return this;
}
/// <summary>
/// Manually set the type of which a typename will be inferred
/// </summary>
public BulkUpdateDescriptor<T, K> Type(Type type)
{
type.ThrowIfNull("type");
this._Type = type;
return this;
}
/// <summary>
/// Manually set the id for the newly created object
/// </summary>
public BulkUpdateDescriptor<T, K> Id(long id)
{
return this.Id(id.ToString(CultureInfo.InvariantCulture));
}
/// <summary>
/// Manually set the id for the newly created object
/// </summary>
public BulkUpdateDescriptor<T, K> Id(string id)
{
this._Id = id;
return this;
}
/// <summary>
/// The object to update, if id is not manually set it will be inferred from the object.
/// Used ONLY to infer the ID see Document() to apply a partial object merge.
/// </summary>
public BulkUpdateDescriptor<T, K> Object(T @object)
{
this._Object = @object;
return this;
}
/// <summary>
/// The partial update document to be merged on to the existing object.
/// </summary>
public BulkUpdateDescriptor<T, K> Document(K @object)
{
this._Document = @object;
return this;
}
public BulkUpdateDescriptor<T, K> DocAsUpsert(bool docAsUpsert = true)
{
this._DocAsUpsert = docAsUpsert;
return this;
}
public BulkUpdateDescriptor<T, K> Lang(string lang)
{
this._Lang = lang;
return this;
}
public BulkUpdateDescriptor<T, K> Script(string script)
{
script.ThrowIfNull("script");
this._Script = script;
return this;
}
public BulkUpdateDescriptor<T, K> Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramDictionary)
{
paramDictionary.ThrowIfNull("paramDictionary");
this._Params = paramDictionary(new FluentDictionary<string, object>());
return this;
}
/// <summary>
/// The full document to be created if an existing document does not exist for a partial merge.
/// </summary>
public BulkUpdateDescriptor<T, K> Upsert(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> upsertValues)
{
upsertValues.ThrowIfNull("upsertValues");
this._Upsert = upsertValues(new FluentDictionary<string, object>());
return this;
}
/// <summary>
/// The full document to be created if an existing document does not exist for a partial merge.
/// </summary>
public BulkUpdateDescriptor<T, K> Upsert(T upsertObject)
{
upsertObject.ThrowIfNull("upsertObject");
this._Upsert = upsertObject;
return this;
}
public BulkUpdateDescriptor<T, K> Version(string version)
{
this._Version = version;
return this;
}
public BulkUpdateDescriptor<T, K> VersionType(string versionType)
{
this._VersionType = versionType;
return this;
}
public BulkUpdateDescriptor<T, K> VersionType(VersionTypeOptions versionType)
{
this._VersionType = versionType.GetStringValue();
return this;
}
public BulkUpdateDescriptor<T, K> Routing(string routing)
{
this._Routing = routing;
return this;
}
public BulkUpdateDescriptor<T, K> Parent(string parent)
{
this._Parent = parent;
return this;
}
public BulkUpdateDescriptor<T, K> Timestamp(long timestamp)
{
this._Timestamp = timestamp;
return this;
}
public BulkUpdateDescriptor<T, K> Ttl(string ttl)
{
this._Ttl = ttl;
return this;
}
public BulkUpdateDescriptor<T, K> RetriesOnConflict(int retriesOnConflict)
{
this._RetriesOnConflict = retriesOnConflict;
return this;
}
}
}