diff --git a/src/Nest/Descriptors.Indices.cs b/src/Nest/Descriptors.Indices.cs
index 63047b5366f..a0eb53ace95 100644
--- a/src/Nest/Descriptors.Indices.cs
+++ b/src/Nest/Descriptors.Indices.cs
@@ -988,6 +988,31 @@ public GetIndexTemplateDescriptor(Names name): base(r => r.Optional("name", name
public GetIndexTemplateDescriptor MasterTimeout(Time mastertimeout) => Qs("master_timeout", mastertimeout);
}
+ ///Descriptor for MigrateToDataStream https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html
+ public partial class MigrateToDataStreamDescriptor : RequestDescriptorBase, IMigrateToDataStreamRequest
+ {
+ internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesMigrateToDataStream;
+
+ protected override HttpMethod HttpMethod => HttpMethod.POST;
+
+ protected override bool SupportsBody => false;
+ ////_data_stream/_migrate/{name}
+ ///this parameter is required
+ public MigrateToDataStreamDescriptor(Name name): base(r => r.Required("name", name))
+ {
+ }
+
+ ///Used for serialization purposes, making sure we have a parameterless constructor
+ [SerializationConstructor]
+ protected MigrateToDataStreamDescriptor(): base()
+ {
+ }
+
+ // values part of the url path
+ Name IMigrateToDataStreamRequest.Name => Self.RouteValues.Get("name");
+ // Request parameters
+ }
+
///Descriptor for Open https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html
public partial class OpenIndexDescriptor : RequestDescriptorBase, IOpenIndexRequest
{
diff --git a/src/Nest/ElasticClient.Indices.cs b/src/Nest/ElasticClient.Indices.cs
index 5987b34ca20..aa037e71317 100644
--- a/src/Nest/ElasticClient.Indices.cs
+++ b/src/Nest/ElasticClient.Indices.cs
@@ -660,6 +660,30 @@ public Task GetMappingAsync(Func
public Task GetTemplateAsync(IGetIndexTemplateRequest request, CancellationToken ct = default) => DoRequestAsync(request, request.RequestParameters, ct);
///
+ /// POST request to the indices.migrate_to_data_stream API, read more about this API online:
+ ///
+ /// https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html
+ ///
+ public MigrateToDataStreamResponse MigrateToDataStream(Name name, Func selector = null) => MigrateToDataStream(selector.InvokeOrDefault(new MigrateToDataStreamDescriptor(name: name)));
+ ///
+ /// POST request to the indices.migrate_to_data_stream API, read more about this API online:
+ ///
+ /// https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html
+ ///
+ public Task MigrateToDataStreamAsync(Name name, Func selector = null, CancellationToken ct = default) => MigrateToDataStreamAsync(selector.InvokeOrDefault(new MigrateToDataStreamDescriptor(name: name)), ct);
+ ///
+ /// POST request to the indices.migrate_to_data_stream API, read more about this API online:
+ ///
+ /// https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html
+ ///
+ public MigrateToDataStreamResponse MigrateToDataStream(IMigrateToDataStreamRequest request) => DoRequest(request, request.RequestParameters);
+ ///
+ /// POST request to the indices.migrate_to_data_stream API, read more about this API online:
+ ///
+ /// https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html
+ ///
+ public Task MigrateToDataStreamAsync(IMigrateToDataStreamRequest request, CancellationToken ct = default) => DoRequestAsync(request, request.RequestParameters, ct);
+ ///
/// POST request to the indices.open API, read more about this API online:
///
/// https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html
diff --git a/src/Nest/Requests.Indices.cs b/src/Nest/Requests.Indices.cs
index fba4210ba98..7ff814fbdb6 100644
--- a/src/Nest/Requests.Indices.cs
+++ b/src/Nest/Requests.Indices.cs
@@ -1705,6 +1705,41 @@ public Time MasterTimeout
}
}
+ [InterfaceDataContract]
+ public partial interface IMigrateToDataStreamRequest : IRequest
+ {
+ [IgnoreDataMember]
+ Name Name
+ {
+ get;
+ }
+ }
+
+ ///Request for MigrateToDataStream https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html
+ public partial class MigrateToDataStreamRequest : PlainRequestBase, IMigrateToDataStreamRequest
+ {
+ protected IMigrateToDataStreamRequest Self => this;
+ internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesMigrateToDataStream;
+ protected override HttpMethod HttpMethod => HttpMethod.POST;
+ protected override bool SupportsBody => false;
+ ////_data_stream/_migrate/{name}
+ ///this parameter is required
+ public MigrateToDataStreamRequest(Name name): base(r => r.Required("name", name))
+ {
+ }
+
+ ///Used for serialization purposes, making sure we have a parameterless constructor
+ [SerializationConstructor]
+ protected MigrateToDataStreamRequest(): base()
+ {
+ }
+
+ // values part of the url path
+ [IgnoreDataMember]
+ Name IMigrateToDataStreamRequest.Name => Self.RouteValues.Get("name");
+ // Request parameters
+ }
+
[InterfaceDataContract]
public partial interface IOpenIndexRequest : IRequest
{
diff --git a/src/Nest/XPack/DataStreams/Migrate/MigrateToDataStreamRequest.cs b/src/Nest/XPack/DataStreams/Migrate/MigrateToDataStreamRequest.cs
new file mode 100644
index 00000000000..029dddcd566
--- /dev/null
+++ b/src/Nest/XPack/DataStreams/Migrate/MigrateToDataStreamRequest.cs
@@ -0,0 +1,40 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace Nest
+{
+ ///
+ /// Converts an index alias to a data stream.
+ ///
+ [MapsApi("indices.migrate_to_data_stream.json")]
+ [ReadAs(typeof(MigrateToDataStreamRequest))]
+ public partial interface IMigrateToDataStreamRequest
+ {
+ }
+
+ ///
+ public partial class MigrateToDataStreamRequest : IMigrateToDataStreamRequest
+ {
+ }
+
+ ///
+ public partial class MigrateToDataStreamDescriptor
+ {
+ }
+}
diff --git a/src/Nest/XPack/DataStreams/Migrate/MigrateToDataStreamResponse.cs b/src/Nest/XPack/DataStreams/Migrate/MigrateToDataStreamResponse.cs
new file mode 100644
index 00000000000..9d939c96342
--- /dev/null
+++ b/src/Nest/XPack/DataStreams/Migrate/MigrateToDataStreamResponse.cs
@@ -0,0 +1,23 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+ namespace Nest
+{
+ public class MigrateToDataStreamResponse : AcknowledgedResponseBase { }
+}
diff --git a/src/Nest/_Generated/ApiUrlsLookup.generated.cs b/src/Nest/_Generated/ApiUrlsLookup.generated.cs
index 8a322a04617..292785f1150 100644
--- a/src/Nest/_Generated/ApiUrlsLookup.generated.cs
+++ b/src/Nest/_Generated/ApiUrlsLookup.generated.cs
@@ -150,6 +150,7 @@ internal static class ApiUrlsLookups
internal static ApiUrls IndicesGetMapping = new ApiUrls(new[]{"_mapping", "{index}/_mapping"});
internal static ApiUrls IndicesGetSettings = new ApiUrls(new[]{"_settings", "{index}/_settings", "{index}/_settings/{name}", "_settings/{name}"});
internal static ApiUrls IndicesGetTemplate = new ApiUrls(new[]{"_template", "_template/{name}"});
+ internal static ApiUrls IndicesMigrateToDataStream = new ApiUrls(new[]{"_data_stream/_migrate/{name}"});
internal static ApiUrls IndicesOpen = new ApiUrls(new[]{"{index}/_open"});
internal static ApiUrls IndicesPutAlias = new ApiUrls(new[]{"{index}/_alias/{name}"});
internal static ApiUrls IndicesPutMapping = new ApiUrls(new[]{"{index}/_mapping"});
diff --git a/tests/Tests/XPack/DataStreams/DataStreamsApiTests.cs b/tests/Tests/XPack/DataStreams/DataStreamsApiTests.cs
index 82d6af81e88..00011671d25 100644
--- a/tests/Tests/XPack/DataStreams/DataStreamsApiTests.cs
+++ b/tests/Tests/XPack/DataStreams/DataStreamsApiTests.cs
@@ -37,7 +37,7 @@ namespace Tests.XPack.DataStreams
[SkipVersion("<7.9.0", "Introduced in 7.9.0")]
public class DataStreamsApiTests : CoordinatedIntegrationTestBase
{
- private static readonly Metric Document = new Metric
+ private static readonly Metric Document = new()
{
Timestamp = new DateTime(2020, 8, 3, 14, 0, 0, DateTimeKind.Utc),
Accept = 3,
@@ -47,13 +47,16 @@ public class DataStreamsApiTests : CoordinatedIntegrationTestBase d.Index(v).Refresh(Refresh.WaitFor),
- (v, c, f) => c.Index(Document, f),
- (v, c, f) => c.IndexAsync(Document, f),
- (v, c, r) => c.Index(r),
- (v, c, r) => c.IndexAsync(r)
+ (v, c, f) => c.Index(Document, f),
+ (v, c, f) => c.IndexAsync(Document, f),
+ (v, c, r) => c.Index(r),
+ (v, c, r) => c.IndexAsync(r)
)
},
{GetDataStreamStep, u =>
@@ -145,6 +148,48 @@ public DataStreamsApiTests(WritableCluster cluster, EndpointUsage usage) : base(
(v, c, r) => c.Indices.DeleteDataStreamAsync(r)
)
},
+ // Used for migrate step
+ {PrepareIndexStep, ">= 7.13.0", u =>
+ u.Calls(
+ v => new CreateIndexRequest($"my-index{v}-test")
+ {
+ Mappings = new TypeMapping
+ {
+ Properties = new Properties
+ {
+ { "@timestamp", new DateNanosProperty() }
+ }
+ }
+ },
+ (v, d) => d.Map(m=> m.Properties(p=> p.DateNanos(dn => dn.Name("@timestamp")))),
+ (v, c, f) => c.Indices.Create($"my-index{v}-test", f),
+ (v, c, f) => c.Indices.CreateAsync($"my-index{v}-test", f),
+ (v, c, r) => c.Indices.Create(r),
+ (v, c, r) => c.Indices.CreateAsync(r)
+ )
+ },
+ // Used for migrate step
+ {PrepareAliasStep,">= 7.13.0", u =>
+ u.Calls(
+ v => new PutAliasRequest($"my-index{v}-test", $"{v}-alias"),
+ (v, d) => d,
+ (v, c, f) => c.Indices.PutAlias($"my-index{v}-test", $"{v}-alias", f),
+ (v, c, f) => c.Indices.PutAliasAsync($"my-index{v}-test", $"{v}-alias", f),
+ (v, c, r) => c.Indices.PutAlias(r),
+ (v, c, r) => c.Indices.PutAliasAsync(r)
+ )
+ },
+ // Migrate to data stream added in 7.13.0
+ {MigrateToDataStreamStep,">= 7.13.0", u =>
+ u.Calls(
+ v => new MigrateToDataStreamRequest($"{v}-alias"),
+ (v, d) => d,
+ (v, c, f) => c.Indices.MigrateToDataStream($"{v}-alias", f),
+ (v, c, f) => c.Indices.MigrateToDataStreamAsync($"{v}-alias", f),
+ (v, c, r) => c.Indices.MigrateToDataStream(r),
+ (v, c, r) => c.Indices.MigrateToDataStreamAsync(r)
+ )
+ },
}) { }
[I] public async Task CreateDataStreamResponse() => await Assert(CreateDataStreamStep, (v, r) =>
@@ -199,5 +244,11 @@ [I] public async Task DeleteDataStreamResponse() => await Assert await Assert(MigrateToDataStreamStep, r =>
+ {
+ r.ShouldBeValid();
+ r.Acknowledged.Should().BeTrue();
+ });
}
}
diff --git a/tests/Tests/XPack/DataStreams/Migrate/MigrateToDataStreamUrlTests.cs b/tests/Tests/XPack/DataStreams/Migrate/MigrateToDataStreamUrlTests.cs
new file mode 100644
index 00000000000..e1067e18870
--- /dev/null
+++ b/tests/Tests/XPack/DataStreams/Migrate/MigrateToDataStreamUrlTests.cs
@@ -0,0 +1,37 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+using System.Threading.Tasks;
+using Elastic.Elasticsearch.Xunit.XunitPlumbing;
+using Nest;
+using Tests.Framework.EndpointTests;
+using static Tests.Framework.EndpointTests.UrlTester;
+
+namespace Tests.XPack.DataStreams.Migrate
+{
+ public class MigrateToDataStreamUrlTests : UrlTestsBase
+ {
+ [U]
+ public override async Task Urls() => await POST("/_data_stream/_migrate/stream")
+ .Fluent(c => c.Indices.MigrateToDataStream("stream", f => f))
+ .Request(c => c.Indices.MigrateToDataStream(new MigrateToDataStreamRequest("stream")))
+ .FluentAsync(c => c.Indices.MigrateToDataStreamAsync("stream", f => f))
+ .RequestAsync(c => c.Indices.MigrateToDataStreamAsync(new MigrateToDataStreamRequest("stream")));
+ }
+}