Skip to content

Commit 92ce48e

Browse files
committed
Add support for clone index API
This commit adds support for the clone index API, introduced in Elasticsearch 7.4.0
1 parent cb97bc4 commit 92ce48e

File tree

11 files changed

+372
-1
lines changed

11 files changed

+372
-1
lines changed

src/CodeGeneration/ApiGenerator/Configuration/CodeConfiguration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public static class CodeConfiguration
4545
"monitoring.bulk.json",
4646
"snapshot.cleanup_repository.json",
4747
"ml.estimate_memory_usage.json",
48-
"indices.clone.json",
4948

5049
"slm.delete_lifecycle.json",
5150
"slm.execute_lifecycle.json",

src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Indices.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,32 @@ public bool? Request
100100
}
101101
}
102102

103+
///<summary>Request options for Clone <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</para></summary>
104+
public class CloneIndexRequestParameters : RequestParameters<CloneIndexRequestParameters>
105+
{
106+
public override HttpMethod DefaultHttpMethod => HttpMethod.PUT;
107+
///<summary>Specify timeout for connection to master</summary>
108+
public TimeSpan MasterTimeout
109+
{
110+
get => Q<TimeSpan>("master_timeout");
111+
set => Q("master_timeout", value);
112+
}
113+
114+
///<summary>Explicit operation timeout</summary>
115+
public TimeSpan Timeout
116+
{
117+
get => Q<TimeSpan>("timeout");
118+
set => Q("timeout", value);
119+
}
120+
121+
///<summary>Set the number of active shards to wait for on the cloned index before the operation returns.</summary>
122+
public string WaitForActiveShards
123+
{
124+
get => Q<string>("wait_for_active_shards");
125+
set => Q("wait_for_active_shards", value);
126+
}
127+
}
128+
103129
///<summary>Request options for Close <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html</para></summary>
104130
public class CloseIndexRequestParameters : RequestParameters<CloseIndexRequestParameters>
105131
{

src/Elasticsearch.Net/ElasticLowLevelClient.Indices.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ public TResponse ClearCache<TResponse>(string index, ClearCacheRequestParameters
8383
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
8484
public Task<TResponse> ClearCacheAsync<TResponse>(string index, ClearCacheRequestParameters requestParameters = null, CancellationToken ctx = default)
8585
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(POST, Url($"{index:index}/_cache/clear"), ctx, null, RequestParams(requestParameters));
86+
///<summary>PUT on /{index}/_clone/{target} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</para></summary>
87+
///<param name = "index">The name of the source index to clone</param>
88+
///<param name = "target">The name of the target index to clone into</param>
89+
///<param name = "body">The configuration for the target index (`settings` and `aliases`)</param>
90+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
91+
public TResponse Clone<TResponse>(string index, string target, PostData body, CloneIndexRequestParameters requestParameters = null)
92+
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(PUT, Url($"{index:index}/_clone/{target:target}"), body, RequestParams(requestParameters));
93+
///<summary>PUT on /{index}/_clone/{target} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</para></summary>
94+
///<param name = "index">The name of the source index to clone</param>
95+
///<param name = "target">The name of the target index to clone into</param>
96+
///<param name = "body">The configuration for the target index (`settings` and `aliases`)</param>
97+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
98+
public Task<TResponse> CloneAsync<TResponse>(string index, string target, PostData body, CloneIndexRequestParameters requestParameters = null, CancellationToken ctx = default)
99+
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(PUT, Url($"{index:index}/_clone/{target:target}"), ctx, body, RequestParams(requestParameters));
86100
///<summary>POST on /{index}/_close <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html</para></summary>
87101
///<param name = "index">A comma separated list of indices to close</param>
88102
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>

src/Nest/Descriptors.Indices.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,40 @@ public ClearCacheDescriptor Fields<T>(params Expression<Func<T, object>>[] field
9999
public ClearCacheDescriptor Request(bool? request = true) => Qs("request", request);
100100
}
101101

102+
///<summary>Descriptor for Clone <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</para></summary>
103+
public partial class CloneIndexDescriptor : RequestDescriptorBase<CloneIndexDescriptor, CloneIndexRequestParameters, ICloneIndexRequest>, ICloneIndexRequest
104+
{
105+
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesClone;
106+
///<summary>/{index}/_clone/{target}</summary>
107+
///<param name = "index">this parameter is required</param>
108+
///<param name = "target">this parameter is required</param>
109+
public CloneIndexDescriptor(IndexName index, IndexName target): base(r => r.Required("index", index).Required("target", target))
110+
{
111+
}
112+
113+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
114+
[SerializationConstructor]
115+
protected CloneIndexDescriptor(): base()
116+
{
117+
}
118+
119+
// values part of the url path
120+
IndexName ICloneIndexRequest.Index => Self.RouteValues.Get<IndexName>("index");
121+
IndexName ICloneIndexRequest.Target => Self.RouteValues.Get<IndexName>("target");
122+
///<summary>The name of the source index to clone</summary>
123+
public CloneIndexDescriptor Index(IndexName index) => Assign(index, (a, v) => a.RouteValues.Required("index", v));
124+
///<summary>a shortcut into calling Index(typeof(TOther))</summary>
125+
public CloneIndexDescriptor Index<TOther>()
126+
where TOther : class => Assign(typeof(TOther), (a, v) => a.RouteValues.Required("index", (IndexName)v));
127+
// Request parameters
128+
///<summary>Specify timeout for connection to master</summary>
129+
public CloneIndexDescriptor MasterTimeout(Time mastertimeout) => Qs("master_timeout", mastertimeout);
130+
///<summary>Explicit operation timeout</summary>
131+
public CloneIndexDescriptor Timeout(Time timeout) => Qs("timeout", timeout);
132+
///<summary>Set the number of active shards to wait for on the cloned index before the operation returns.</summary>
133+
public CloneIndexDescriptor WaitForActiveShards(string waitforactiveshards) => Qs("wait_for_active_shards", waitforactiveshards);
134+
}
135+
102136
///<summary>Descriptor for Close <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html</para></summary>
103137
public partial class CloseIndexDescriptor : RequestDescriptorBase<CloseIndexDescriptor, CloseIndexRequestParameters, ICloseIndexRequest>, ICloseIndexRequest
104138
{

src/Nest/ElasticClient.Indices.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,30 @@ internal IndicesNamespace(ElasticClient client): base(client)
8585
/// </summary>
8686
public Task<ClearCacheResponse> ClearCacheAsync(IClearCacheRequest request, CancellationToken ct = default) => DoRequestAsync<IClearCacheRequest, ClearCacheResponse>(request, request.RequestParameters, ct);
8787
/// <summary>
88+
/// <c>PUT</c> request to the <c>indices.clone</c> API, read more about this API online:
89+
/// <para></para>
90+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</a>
91+
/// </summary>
92+
public CloneIndexResponse Clone(IndexName index, IndexName target, Func<CloneIndexDescriptor, ICloneIndexRequest> selector = null) => Clone(selector.InvokeOrDefault(new CloneIndexDescriptor(index: index, target: target)));
93+
/// <summary>
94+
/// <c>PUT</c> request to the <c>indices.clone</c> API, read more about this API online:
95+
/// <para></para>
96+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</a>
97+
/// </summary>
98+
public Task<CloneIndexResponse> CloneAsync(IndexName index, IndexName target, Func<CloneIndexDescriptor, ICloneIndexRequest> selector = null, CancellationToken ct = default) => CloneAsync(selector.InvokeOrDefault(new CloneIndexDescriptor(index: index, target: target)), ct);
99+
/// <summary>
100+
/// <c>PUT</c> request to the <c>indices.clone</c> API, read more about this API online:
101+
/// <para></para>
102+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</a>
103+
/// </summary>
104+
public CloneIndexResponse Clone(ICloneIndexRequest request) => DoRequest<ICloneIndexRequest, CloneIndexResponse>(request, request.RequestParameters);
105+
/// <summary>
106+
/// <c>PUT</c> request to the <c>indices.clone</c> API, read more about this API online:
107+
/// <para></para>
108+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</a>
109+
/// </summary>
110+
public Task<CloneIndexResponse> CloneAsync(ICloneIndexRequest request, CancellationToken ct = default) => DoRequestAsync<ICloneIndexRequest, CloneIndexResponse>(request, request.RequestParameters, ct);
111+
/// <summary>
88112
/// <c>POST</c> request to the <c>indices.close</c> API, read more about this API online:
89113
/// <para></para>
90114
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html</a>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
4+
namespace Nest
5+
{
6+
/// <summary>
7+
/// A request to the clone index API
8+
/// </summary>
9+
[MapsApi("indices.clone")]
10+
[ReadAs(typeof(CloneIndexRequest))]
11+
public partial interface ICloneIndexRequest
12+
{
13+
/// <summary>
14+
/// The aliases to apply to the target index
15+
/// </summary>
16+
[DataMember(Name ="aliases")]
17+
IAliases Aliases { get; set; }
18+
19+
/// <summary>
20+
/// The settings to apply to the target index
21+
/// </summary>
22+
[DataMember(Name ="settings")]
23+
IIndexSettings Settings { get; set; }
24+
}
25+
26+
/// <inheritdoc cref="ICloneIndexRequest" />
27+
public partial class CloneIndexRequest
28+
{
29+
/// <inheritdoc />
30+
public IAliases Aliases { get; set; }
31+
32+
/// <inheritdoc />
33+
public IIndexSettings Settings { get; set; }
34+
}
35+
36+
/// <inheritdoc cref="ICloneIndexRequest" />
37+
public partial class CloneIndexDescriptor
38+
{
39+
IAliases ICloneIndexRequest.Aliases { get; set; }
40+
IIndexSettings ICloneIndexRequest.Settings { get; set; }
41+
42+
/// <inheritdoc cref="ICloneIndexRequest.Settings"/>
43+
public CloneIndexDescriptor Settings(Func<IndexSettingsDescriptor, IPromise<IIndexSettings>> selector) =>
44+
Assign(selector, (a, v) => a.Settings = v?.Invoke(new IndexSettingsDescriptor())?.Value);
45+
46+
/// <inheritdoc cref="ICloneIndexRequest.Aliases"/>
47+
public CloneIndexDescriptor Aliases(Func<AliasesDescriptor, IPromise<IAliases>> selector) =>
48+
Assign(selector, (a, v) => a.Aliases = v?.Invoke(new AliasesDescriptor())?.Value);
49+
}
50+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Nest
4+
{
5+
public class CloneIndexResponse : AcknowledgedResponseBase
6+
{
7+
[DataMember(Name = "shards_acknowledged")]
8+
public bool ShardsAcknowledged { get; set; }
9+
10+
/// <summary>
11+
/// The target index created
12+
/// </summary>
13+
[DataMember(Name = "index")]
14+
public string Index { get; set; }
15+
}
16+
}

src/Nest/Requests.Indices.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,68 @@ public bool? Request
146146
}
147147
}
148148

149+
[InterfaceDataContract]
150+
public partial interface ICloneIndexRequest : IRequest<CloneIndexRequestParameters>
151+
{
152+
[IgnoreDataMember]
153+
IndexName Index
154+
{
155+
get;
156+
}
157+
158+
[IgnoreDataMember]
159+
IndexName Target
160+
{
161+
get;
162+
}
163+
}
164+
165+
///<summary>Request for Clone <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</para></summary>
166+
public partial class CloneIndexRequest : PlainRequestBase<CloneIndexRequestParameters>, ICloneIndexRequest
167+
{
168+
protected ICloneIndexRequest Self => this;
169+
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesClone;
170+
///<summary>/{index}/_clone/{target}</summary>
171+
///<param name = "index">this parameter is required</param>
172+
///<param name = "target">this parameter is required</param>
173+
public CloneIndexRequest(IndexName index, IndexName target): base(r => r.Required("index", index).Required("target", target))
174+
{
175+
}
176+
177+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
178+
[SerializationConstructor]
179+
protected CloneIndexRequest(): base()
180+
{
181+
}
182+
183+
// values part of the url path
184+
[IgnoreDataMember]
185+
IndexName ICloneIndexRequest.Index => Self.RouteValues.Get<IndexName>("index");
186+
[IgnoreDataMember]
187+
IndexName ICloneIndexRequest.Target => Self.RouteValues.Get<IndexName>("target");
188+
// Request parameters
189+
///<summary>Specify timeout for connection to master</summary>
190+
public Time MasterTimeout
191+
{
192+
get => Q<Time>("master_timeout");
193+
set => Q("master_timeout", value);
194+
}
195+
196+
///<summary>Explicit operation timeout</summary>
197+
public Time Timeout
198+
{
199+
get => Q<Time>("timeout");
200+
set => Q("timeout", value);
201+
}
202+
203+
///<summary>Set the number of active shards to wait for on the cloned index before the operation returns.</summary>
204+
public string WaitForActiveShards
205+
{
206+
get => Q<string>("wait_for_active_shards");
207+
set => Q("wait_for_active_shards", value);
208+
}
209+
}
210+
149211
[InterfaceDataContract]
150212
public partial interface ICloseIndexRequest : IRequest<CloseIndexRequestParameters>
151213
{

src/Nest/_Generated/ApiUrlsLookup.generated.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ internal static class ApiUrlsLookups
8787
internal static ApiUrls NoNamespaceIndex = new ApiUrls(new[]{"{index}/_doc/{id}", "{index}/_doc"});
8888
internal static ApiUrls IndicesAnalyze = new ApiUrls(new[]{"_analyze", "{index}/_analyze"});
8989
internal static ApiUrls IndicesClearCache = new ApiUrls(new[]{"_cache/clear", "{index}/_cache/clear"});
90+
internal static ApiUrls IndicesClone = new ApiUrls(new[]{"{index}/_clone/{target}"});
9091
internal static ApiUrls IndicesClose = new ApiUrls(new[]{"{index}/_close"});
9192
internal static ApiUrls IndicesCreate = new ApiUrls(new[]{"{index}"});
9293
internal static ApiUrls IndicesDelete = new ApiUrls(new[]{"{index}"});

0 commit comments

Comments
 (0)