Skip to content

Commit e821cf2

Browse files
russcamMpdreamz
andcommitted
Add support for Transforms APIs (#4683)
Relates: #4610 This commit adds support for the transform APIs, which are part of Elasticsearch 7.7.0+, default distribution. Co-authored-by: Martijn Laarman <Mpdreamz@gmail.com> (cherry picked from commit fbdc4ff)
1 parent 7ee66fa commit e821cf2

35 files changed

+2556
-24
lines changed

src/ApiGenerator/Configuration/CodeConfiguration.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@ public static class CodeConfiguration
8080
"cluster.get_component_template.json",
8181
"cluster.put_component_template.json",
8282
"cluster.exists_component_template.json",
83-
"transform.delete_transform.json",
84-
"transform.get_transform.json",
85-
"transform.get_transform_stats.json",
86-
"transform.preview_transform.json",
87-
"transform.put_transform.json",
88-
"transform.start_transform.json",
89-
"transform.stop_transform.json",
90-
"transform.update_transform.json",
9183
};
9284

9385

src/Nest/CommonAbstractions/Infer/Indices/IndicesFormatter.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,28 @@ internal class IndicesFormatter : IJsonFormatter<Indices>
77
{
88
public Indices Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
99
{
10-
if (reader.GetCurrentJsonToken() != JsonToken.BeginArray)
10+
switch (reader.GetCurrentJsonToken())
1111
{
12-
reader.ReadNextBlock();
13-
return null;
14-
}
15-
16-
var indices = new List<IndexName>();
17-
var count = 0;
18-
while (reader.ReadIsInArray(ref count))
19-
{
20-
var index = reader.ReadString();
21-
indices.Add(index);
12+
case JsonToken.BeginArray:
13+
{
14+
var indices = new List<IndexName>();
15+
var count = 0;
16+
while (reader.ReadIsInArray(ref count))
17+
{
18+
var index = reader.ReadString();
19+
indices.Add(index);
20+
}
21+
return new Indices(indices);
22+
}
23+
case JsonToken.String:
24+
{
25+
Indices indices = reader.ReadString();
26+
return indices;
27+
}
28+
default:
29+
reader.ReadNextBlock();
30+
return null;
2231
}
23-
return new Indices(indices);
2432
}
2533

2634
public void Serialize(ref JsonWriter writer, Indices value, IJsonFormatterResolver formatterResolver)

src/Nest/CommonOptions/DateMath/DateMathTime.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using System;
22
using System.Globalization;
33
using System.Text.RegularExpressions;
4+
using Elasticsearch.Net.Utf8Json;
45

56
namespace Nest
67
{
78
/// <summary>
89
/// A time representation for use within <see cref="DateMath" /> expressions.
910
/// </summary>
11+
[JsonFormatter(typeof(DateMathTimeFormatter))]
1012
public class DateMathTime : IComparable<DateMathTime>, IEquatable<DateMathTime>
1113
{
1214
private const double MillisecondsInADay = MillisecondsInAnHour * 24;
@@ -300,7 +302,7 @@ private static bool TryGetIntegerGreaterThanZero(double d, out int value)
300302
public static bool operator >=(DateMathTime left, DateMathTime right) => left.CompareTo(right) > 0 || left.Equals(right);
301303

302304
public static bool operator ==(DateMathTime left, DateMathTime right) =>
303-
ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.Equals(right);
305+
left?.Equals(right) ?? ReferenceEquals(right, null);
304306

305307
public static bool operator !=(DateMathTime left, DateMathTime right) => !(left == right);
306308

@@ -318,4 +320,15 @@ public override bool Equals(object obj)
318320
// ReSharper disable once NonReadonlyMemberInGetHashCode
319321
public override int GetHashCode() => _approximateSeconds.GetHashCode();
320322
}
323+
324+
internal class DateMathTimeFormatter: IJsonFormatter<DateMathTime>
325+
{
326+
public void Serialize(ref JsonWriter writer, DateMathTime value, IJsonFormatterResolver formatterResolver)
327+
{
328+
if (value is null) writer.WriteNull();
329+
else writer.WriteString(value.ToString());
330+
}
331+
332+
public DateMathTime Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) => reader.ReadString();
333+
}
321334
}

src/Nest/Descriptors.Transform.cs

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
2+
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
3+
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
4+
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
5+
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
6+
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
7+
// -----------------------------------------------
8+
//
9+
// This file is automatically generated
10+
// Please do not edit these files manually
11+
// Run the following in the root of the repos:
12+
//
13+
// *NIX : ./build.sh codegen
14+
// Windows : build.bat codegen
15+
//
16+
// -----------------------------------------------
17+
// ReSharper disable RedundantUsingDirective
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Linq;
21+
using System.Text;
22+
using System.Linq.Expressions;
23+
using Elasticsearch.Net;
24+
using Elasticsearch.Net.Utf8Json;
25+
using Elasticsearch.Net.Specification.TransformApi;
26+
27+
// ReSharper disable RedundantBaseConstructorCall
28+
// ReSharper disable UnusedTypeParameter
29+
// ReSharper disable PartialMethodWithSinglePart
30+
// ReSharper disable RedundantNameQualifier
31+
namespace Nest
32+
{
33+
///<summary>Descriptor for Delete <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-transform.html</para></summary>
34+
public partial class DeleteTransformDescriptor : RequestDescriptorBase<DeleteTransformDescriptor, DeleteTransformRequestParameters, IDeleteTransformRequest>, IDeleteTransformRequest
35+
{
36+
internal override ApiUrls ApiUrls => ApiUrlsLookups.TransformDelete;
37+
///<summary>/_transform/{transform_id}</summary>
38+
///<param name = "transformId">this parameter is required</param>
39+
public DeleteTransformDescriptor(Id transformId): base(r => r.Required("transform_id", transformId))
40+
{
41+
}
42+
43+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
44+
[SerializationConstructor]
45+
protected DeleteTransformDescriptor(): base()
46+
{
47+
}
48+
49+
// values part of the url path
50+
Id IDeleteTransformRequest.TransformId => Self.RouteValues.Get<Id>("transform_id");
51+
// Request parameters
52+
///<summary>When `true`, the transform is deleted regardless of its current state. The default value is `false`, meaning that the transform must be `stopped` before it can be deleted.</summary>
53+
public DeleteTransformDescriptor Force(bool? force = true) => Qs("force", force);
54+
}
55+
56+
///<summary>Descriptor for Get <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/get-transform.html</para></summary>
57+
public partial class GetTransformDescriptor : RequestDescriptorBase<GetTransformDescriptor, GetTransformRequestParameters, IGetTransformRequest>, IGetTransformRequest
58+
{
59+
internal override ApiUrls ApiUrls => ApiUrlsLookups.TransformGet;
60+
///<summary>/_transform/{transform_id}</summary>
61+
///<param name = "transformId">Optional, accepts null</param>
62+
public GetTransformDescriptor(Id transformId): base(r => r.Optional("transform_id", transformId))
63+
{
64+
}
65+
66+
///<summary>/_transform</summary>
67+
public GetTransformDescriptor(): base()
68+
{
69+
}
70+
71+
// values part of the url path
72+
Id IGetTransformRequest.TransformId => Self.RouteValues.Get<Id>("transform_id");
73+
///<summary>The id or comma delimited list of id expressions of the transforms to get, '_all' or '*' implies get all transforms</summary>
74+
public GetTransformDescriptor TransformId(Id transformId) => Assign(transformId, (a, v) => a.RouteValues.Optional("transform_id", v));
75+
// Request parameters
76+
///<summary>Whether to ignore if a wildcard expression matches no transforms. (This includes `_all` string or when no transforms have been specified)</summary>
77+
public GetTransformDescriptor AllowNoMatch(bool? allownomatch = true) => Qs("allow_no_match", allownomatch);
78+
///<summary>skips a number of transform configs, defaults to 0</summary>
79+
public GetTransformDescriptor From(int? from) => Qs("from", from);
80+
///<summary>specifies a max number of transforms to get, defaults to 100</summary>
81+
public GetTransformDescriptor Size(int? size) => Qs("size", size);
82+
}
83+
84+
///<summary>Descriptor for GetStats <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/get-transform-stats.html</para></summary>
85+
public partial class GetTransformStatsDescriptor : RequestDescriptorBase<GetTransformStatsDescriptor, GetTransformStatsRequestParameters, IGetTransformStatsRequest>, IGetTransformStatsRequest
86+
{
87+
internal override ApiUrls ApiUrls => ApiUrlsLookups.TransformGetStats;
88+
///<summary>/_transform/{transform_id}/_stats</summary>
89+
///<param name = "transformId">this parameter is required</param>
90+
public GetTransformStatsDescriptor(Id transformId): base(r => r.Required("transform_id", transformId))
91+
{
92+
}
93+
94+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
95+
[SerializationConstructor]
96+
protected GetTransformStatsDescriptor(): base()
97+
{
98+
}
99+
100+
// values part of the url path
101+
Id IGetTransformStatsRequest.TransformId => Self.RouteValues.Get<Id>("transform_id");
102+
// Request parameters
103+
///<summary>Whether to ignore if a wildcard expression matches no transforms. (This includes `_all` string or when no transforms have been specified)</summary>
104+
public GetTransformStatsDescriptor AllowNoMatch(bool? allownomatch = true) => Qs("allow_no_match", allownomatch);
105+
///<summary>skips a number of transform stats, defaults to 0</summary>
106+
public GetTransformStatsDescriptor From(long? from) => Qs("from", from);
107+
///<summary>specifies a max number of transform stats to get, defaults to 100</summary>
108+
public GetTransformStatsDescriptor Size(long? size) => Qs("size", size);
109+
}
110+
111+
///<summary>Descriptor for Preview <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/preview-transform.html</para></summary>
112+
public partial class PreviewTransformDescriptor<TDocument> : RequestDescriptorBase<PreviewTransformDescriptor<TDocument>, PreviewTransformRequestParameters, IPreviewTransformRequest>, IPreviewTransformRequest
113+
{
114+
internal override ApiUrls ApiUrls => ApiUrlsLookups.TransformPreview;
115+
// values part of the url path
116+
// Request parameters
117+
}
118+
119+
///<summary>Descriptor for Put <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/put-transform.html</para></summary>
120+
public partial class PutTransformDescriptor<TDocument> : RequestDescriptorBase<PutTransformDescriptor<TDocument>, PutTransformRequestParameters, IPutTransformRequest>, IPutTransformRequest
121+
{
122+
internal override ApiUrls ApiUrls => ApiUrlsLookups.TransformPut;
123+
///<summary>/_transform/{transform_id}</summary>
124+
///<param name = "transformId">this parameter is required</param>
125+
public PutTransformDescriptor(Id transformId): base(r => r.Required("transform_id", transformId))
126+
{
127+
}
128+
129+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
130+
[SerializationConstructor]
131+
protected PutTransformDescriptor(): base()
132+
{
133+
}
134+
135+
// values part of the url path
136+
Id IPutTransformRequest.TransformId => Self.RouteValues.Get<Id>("transform_id");
137+
// Request parameters
138+
///<summary>If validations should be deferred until transform starts, defaults to false.</summary>
139+
public PutTransformDescriptor<TDocument> DeferValidation(bool? defervalidation = true) => Qs("defer_validation", defervalidation);
140+
}
141+
142+
///<summary>Descriptor for Start <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/start-transform.html</para></summary>
143+
public partial class StartTransformDescriptor : RequestDescriptorBase<StartTransformDescriptor, StartTransformRequestParameters, IStartTransformRequest>, IStartTransformRequest
144+
{
145+
internal override ApiUrls ApiUrls => ApiUrlsLookups.TransformStart;
146+
///<summary>/_transform/{transform_id}/_start</summary>
147+
///<param name = "transformId">this parameter is required</param>
148+
public StartTransformDescriptor(Id transformId): base(r => r.Required("transform_id", transformId))
149+
{
150+
}
151+
152+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
153+
[SerializationConstructor]
154+
protected StartTransformDescriptor(): base()
155+
{
156+
}
157+
158+
// values part of the url path
159+
Id IStartTransformRequest.TransformId => Self.RouteValues.Get<Id>("transform_id");
160+
// Request parameters
161+
///<summary>Controls the time to wait for the transform to start</summary>
162+
public StartTransformDescriptor Timeout(Time timeout) => Qs("timeout", timeout);
163+
}
164+
165+
///<summary>Descriptor for Stop <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/stop-transform.html</para></summary>
166+
public partial class StopTransformDescriptor : RequestDescriptorBase<StopTransformDescriptor, StopTransformRequestParameters, IStopTransformRequest>, IStopTransformRequest
167+
{
168+
internal override ApiUrls ApiUrls => ApiUrlsLookups.TransformStop;
169+
///<summary>/_transform/{transform_id}/_stop</summary>
170+
///<param name = "transformId">this parameter is required</param>
171+
public StopTransformDescriptor(Id transformId): base(r => r.Required("transform_id", transformId))
172+
{
173+
}
174+
175+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
176+
[SerializationConstructor]
177+
protected StopTransformDescriptor(): base()
178+
{
179+
}
180+
181+
// values part of the url path
182+
Id IStopTransformRequest.TransformId => Self.RouteValues.Get<Id>("transform_id");
183+
// Request parameters
184+
///<summary>Whether to ignore if a wildcard expression matches no transforms. (This includes `_all` string or when no transforms have been specified)</summary>
185+
public StopTransformDescriptor AllowNoMatch(bool? allownomatch = true) => Qs("allow_no_match", allownomatch);
186+
///<summary>Whether to force stop a failed transform or not. Default to false</summary>
187+
public StopTransformDescriptor Force(bool? force = true) => Qs("force", force);
188+
///<summary>Controls the time to wait until the transform has stopped. Default to 30 seconds</summary>
189+
public StopTransformDescriptor Timeout(Time timeout) => Qs("timeout", timeout);
190+
///<summary>Whether to wait for the transform to reach a checkpoint before stopping. Default to false</summary>
191+
public StopTransformDescriptor WaitForCheckpoint(bool? waitforcheckpoint = true) => Qs("wait_for_checkpoint", waitforcheckpoint);
192+
///<summary>Whether to wait for the transform to fully stop before returning or not. Default to false</summary>
193+
public StopTransformDescriptor WaitForCompletion(bool? waitforcompletion = true) => Qs("wait_for_completion", waitforcompletion);
194+
}
195+
196+
///<summary>Descriptor for Update <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/update-transform.html</para></summary>
197+
public partial class UpdateTransformDescriptor<TDocument> : RequestDescriptorBase<UpdateTransformDescriptor<TDocument>, UpdateTransformRequestParameters, IUpdateTransformRequest>, IUpdateTransformRequest
198+
{
199+
internal override ApiUrls ApiUrls => ApiUrlsLookups.TransformUpdate;
200+
///<summary>/_transform/{transform_id}/_update</summary>
201+
///<param name = "transformId">this parameter is required</param>
202+
public UpdateTransformDescriptor(Id transformId): base(r => r.Required("transform_id", transformId))
203+
{
204+
}
205+
206+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
207+
[SerializationConstructor]
208+
protected UpdateTransformDescriptor(): base()
209+
{
210+
}
211+
212+
// values part of the url path
213+
Id IUpdateTransformRequest.TransformId => Self.RouteValues.Get<Id>("transform_id");
214+
// Request parameters
215+
///<summary>If validations should be deferred until transform starts, defaults to false.</summary>
216+
public UpdateTransformDescriptor<TDocument> DeferValidation(bool? defervalidation = true) => Qs("defer_validation", defervalidation);
217+
}
218+
}

src/Nest/ElasticClient.NoNamespace.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
using Nest.Specification.SnapshotLifecycleManagementApi;
3939
using Nest.Specification.SqlApi;
4040
using Nest.Specification.TasksApi;
41+
using Nest.Specification.TransformApi;
4142
using Nest.Specification.WatcherApi;
4243
using Nest.Specification.XPackApi;
4344

@@ -182,6 +183,13 @@ public TasksNamespace Tasks
182183
private set;
183184
}
184185

186+
///<summary>Transform APIs</summary>
187+
public TransformNamespace Transform
188+
{
189+
get;
190+
private set;
191+
}
192+
185193
///<summary>Watcher APIs</summary>
186194
public WatcherNamespace Watcher
187195
{
@@ -217,6 +225,7 @@ partial void SetupNamespaces()
217225
SnapshotLifecycleManagement = new SnapshotLifecycleManagementNamespace(this);
218226
Sql = new SqlNamespace(this);
219227
Tasks = new TasksNamespace(this);
228+
Transform = new TransformNamespace(this);
220229
Watcher = new WatcherNamespace(this);
221230
XPack = new XPackNamespace(this);
222231
}

0 commit comments

Comments
 (0)