Skip to content

Commit

Permalink
Add support for clone index API
Browse files Browse the repository at this point in the history
This commit adds support for the clone index API, introduced in Elasticsearch 7.4.0
  • Loading branch information
russcam committed Oct 11, 2019
1 parent cb97bc4 commit 92ce48e
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public static class CodeConfiguration
"monitoring.bulk.json",
"snapshot.cleanup_repository.json",
"ml.estimate_memory_usage.json",
"indices.clone.json",

"slm.delete_lifecycle.json",
"slm.execute_lifecycle.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,32 @@ public bool? Request
}
}

///<summary>Request options for Clone <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</para></summary>
public class CloneIndexRequestParameters : RequestParameters<CloneIndexRequestParameters>
{
public override HttpMethod DefaultHttpMethod => HttpMethod.PUT;
///<summary>Specify timeout for connection to master</summary>
public TimeSpan MasterTimeout
{
get => Q<TimeSpan>("master_timeout");
set => Q("master_timeout", value);
}

///<summary>Explicit operation timeout</summary>
public TimeSpan Timeout
{
get => Q<TimeSpan>("timeout");
set => Q("timeout", value);
}

///<summary>Set the number of active shards to wait for on the cloned index before the operation returns.</summary>
public string WaitForActiveShards
{
get => Q<string>("wait_for_active_shards");
set => Q("wait_for_active_shards", value);
}
}

///<summary>Request options for Close <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html</para></summary>
public class CloseIndexRequestParameters : RequestParameters<CloseIndexRequestParameters>
{
Expand Down
14 changes: 14 additions & 0 deletions src/Elasticsearch.Net/ElasticLowLevelClient.Indices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ public TResponse ClearCache<TResponse>(string index, ClearCacheRequestParameters
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public Task<TResponse> ClearCacheAsync<TResponse>(string index, ClearCacheRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(POST, Url($"{index:index}/_cache/clear"), ctx, null, RequestParams(requestParameters));
///<summary>PUT on /{index}/_clone/{target} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</para></summary>
///<param name = "index">The name of the source index to clone</param>
///<param name = "target">The name of the target index to clone into</param>
///<param name = "body">The configuration for the target index (`settings` and `aliases`)</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public TResponse Clone<TResponse>(string index, string target, PostData body, CloneIndexRequestParameters requestParameters = null)
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(PUT, Url($"{index:index}/_clone/{target:target}"), body, RequestParams(requestParameters));
///<summary>PUT on /{index}/_clone/{target} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</para></summary>
///<param name = "index">The name of the source index to clone</param>
///<param name = "target">The name of the target index to clone into</param>
///<param name = "body">The configuration for the target index (`settings` and `aliases`)</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public Task<TResponse> CloneAsync<TResponse>(string index, string target, PostData body, CloneIndexRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(PUT, Url($"{index:index}/_clone/{target:target}"), ctx, body, RequestParams(requestParameters));
///<summary>POST on /{index}/_close <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html</para></summary>
///<param name = "index">A comma separated list of indices to close</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
Expand Down
34 changes: 34 additions & 0 deletions src/Nest/Descriptors.Indices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,40 @@ public ClearCacheDescriptor Fields<T>(params Expression<Func<T, object>>[] field
public ClearCacheDescriptor Request(bool? request = true) => Qs("request", request);
}

///<summary>Descriptor for Clone <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</para></summary>
public partial class CloneIndexDescriptor : RequestDescriptorBase<CloneIndexDescriptor, CloneIndexRequestParameters, ICloneIndexRequest>, ICloneIndexRequest
{
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesClone;
///<summary>/{index}/_clone/{target}</summary>
///<param name = "index">this parameter is required</param>
///<param name = "target">this parameter is required</param>
public CloneIndexDescriptor(IndexName index, IndexName target): base(r => r.Required("index", index).Required("target", target))
{
}

///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
[SerializationConstructor]
protected CloneIndexDescriptor(): base()
{
}

// values part of the url path
IndexName ICloneIndexRequest.Index => Self.RouteValues.Get<IndexName>("index");
IndexName ICloneIndexRequest.Target => Self.RouteValues.Get<IndexName>("target");
///<summary>The name of the source index to clone</summary>
public CloneIndexDescriptor Index(IndexName index) => Assign(index, (a, v) => a.RouteValues.Required("index", v));
///<summary>a shortcut into calling Index(typeof(TOther))</summary>
public CloneIndexDescriptor Index<TOther>()
where TOther : class => Assign(typeof(TOther), (a, v) => a.RouteValues.Required("index", (IndexName)v));
// Request parameters
///<summary>Specify timeout for connection to master</summary>
public CloneIndexDescriptor MasterTimeout(Time mastertimeout) => Qs("master_timeout", mastertimeout);
///<summary>Explicit operation timeout</summary>
public CloneIndexDescriptor Timeout(Time timeout) => Qs("timeout", timeout);
///<summary>Set the number of active shards to wait for on the cloned index before the operation returns.</summary>
public CloneIndexDescriptor WaitForActiveShards(string waitforactiveshards) => Qs("wait_for_active_shards", waitforactiveshards);
}

///<summary>Descriptor for Close <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html</para></summary>
public partial class CloseIndexDescriptor : RequestDescriptorBase<CloseIndexDescriptor, CloseIndexRequestParameters, ICloseIndexRequest>, ICloseIndexRequest
{
Expand Down
24 changes: 24 additions & 0 deletions src/Nest/ElasticClient.Indices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@ internal IndicesNamespace(ElasticClient client): base(client)
/// </summary>
public Task<ClearCacheResponse> ClearCacheAsync(IClearCacheRequest request, CancellationToken ct = default) => DoRequestAsync<IClearCacheRequest, ClearCacheResponse>(request, request.RequestParameters, ct);
/// <summary>
/// <c>PUT</c> request to the <c>indices.clone</c> API, read more about this API online:
/// <para></para>
/// <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>
/// </summary>
public CloneIndexResponse Clone(IndexName index, IndexName target, Func<CloneIndexDescriptor, ICloneIndexRequest> selector = null) => Clone(selector.InvokeOrDefault(new CloneIndexDescriptor(index: index, target: target)));
/// <summary>
/// <c>PUT</c> request to the <c>indices.clone</c> API, read more about this API online:
/// <para></para>
/// <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>
/// </summary>
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);
/// <summary>
/// <c>PUT</c> request to the <c>indices.clone</c> API, read more about this API online:
/// <para></para>
/// <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>
/// </summary>
public CloneIndexResponse Clone(ICloneIndexRequest request) => DoRequest<ICloneIndexRequest, CloneIndexResponse>(request, request.RequestParameters);
/// <summary>
/// <c>PUT</c> request to the <c>indices.clone</c> API, read more about this API online:
/// <para></para>
/// <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>
/// </summary>
public Task<CloneIndexResponse> CloneAsync(ICloneIndexRequest request, CancellationToken ct = default) => DoRequestAsync<ICloneIndexRequest, CloneIndexResponse>(request, request.RequestParameters, ct);
/// <summary>
/// <c>POST</c> request to the <c>indices.close</c> API, read more about this API online:
/// <para></para>
/// <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>
Expand Down
50 changes: 50 additions & 0 deletions src/Nest/Indices/IndexManagement/CloneIndex/CloneIndexRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Runtime.Serialization;

namespace Nest
{
/// <summary>
/// A request to the clone index API
/// </summary>
[MapsApi("indices.clone")]
[ReadAs(typeof(CloneIndexRequest))]
public partial interface ICloneIndexRequest
{
/// <summary>
/// The aliases to apply to the target index
/// </summary>
[DataMember(Name ="aliases")]
IAliases Aliases { get; set; }

/// <summary>
/// The settings to apply to the target index
/// </summary>
[DataMember(Name ="settings")]
IIndexSettings Settings { get; set; }
}

/// <inheritdoc cref="ICloneIndexRequest" />
public partial class CloneIndexRequest
{
/// <inheritdoc />
public IAliases Aliases { get; set; }

/// <inheritdoc />
public IIndexSettings Settings { get; set; }
}

/// <inheritdoc cref="ICloneIndexRequest" />
public partial class CloneIndexDescriptor
{
IAliases ICloneIndexRequest.Aliases { get; set; }
IIndexSettings ICloneIndexRequest.Settings { get; set; }

/// <inheritdoc cref="ICloneIndexRequest.Settings"/>
public CloneIndexDescriptor Settings(Func<IndexSettingsDescriptor, IPromise<IIndexSettings>> selector) =>
Assign(selector, (a, v) => a.Settings = v?.Invoke(new IndexSettingsDescriptor())?.Value);

/// <inheritdoc cref="ICloneIndexRequest.Aliases"/>
public CloneIndexDescriptor Aliases(Func<AliasesDescriptor, IPromise<IAliases>> selector) =>
Assign(selector, (a, v) => a.Aliases = v?.Invoke(new AliasesDescriptor())?.Value);
}
}
16 changes: 16 additions & 0 deletions src/Nest/Indices/IndexManagement/CloneIndex/CloneIndexResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Runtime.Serialization;

namespace Nest
{
public class CloneIndexResponse : AcknowledgedResponseBase
{
[DataMember(Name = "shards_acknowledged")]
public bool ShardsAcknowledged { get; set; }

/// <summary>
/// The target index created
/// </summary>
[DataMember(Name = "index")]
public string Index { get; set; }
}
}
62 changes: 62 additions & 0 deletions src/Nest/Requests.Indices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,68 @@ public bool? Request
}
}

[InterfaceDataContract]
public partial interface ICloneIndexRequest : IRequest<CloneIndexRequestParameters>
{
[IgnoreDataMember]
IndexName Index
{
get;
}

[IgnoreDataMember]
IndexName Target
{
get;
}
}

///<summary>Request for Clone <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html</para></summary>
public partial class CloneIndexRequest : PlainRequestBase<CloneIndexRequestParameters>, ICloneIndexRequest
{
protected ICloneIndexRequest Self => this;
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesClone;
///<summary>/{index}/_clone/{target}</summary>
///<param name = "index">this parameter is required</param>
///<param name = "target">this parameter is required</param>
public CloneIndexRequest(IndexName index, IndexName target): base(r => r.Required("index", index).Required("target", target))
{
}

///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
[SerializationConstructor]
protected CloneIndexRequest(): base()
{
}

// values part of the url path
[IgnoreDataMember]
IndexName ICloneIndexRequest.Index => Self.RouteValues.Get<IndexName>("index");
[IgnoreDataMember]
IndexName ICloneIndexRequest.Target => Self.RouteValues.Get<IndexName>("target");
// Request parameters
///<summary>Specify timeout for connection to master</summary>
public Time MasterTimeout
{
get => Q<Time>("master_timeout");
set => Q("master_timeout", value);
}

///<summary>Explicit operation timeout</summary>
public Time Timeout
{
get => Q<Time>("timeout");
set => Q("timeout", value);
}

///<summary>Set the number of active shards to wait for on the cloned index before the operation returns.</summary>
public string WaitForActiveShards
{
get => Q<string>("wait_for_active_shards");
set => Q("wait_for_active_shards", value);
}
}

[InterfaceDataContract]
public partial interface ICloseIndexRequest : IRequest<CloseIndexRequestParameters>
{
Expand Down
1 change: 1 addition & 0 deletions src/Nest/_Generated/ApiUrlsLookup.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ internal static class ApiUrlsLookups
internal static ApiUrls NoNamespaceIndex = new ApiUrls(new[]{"{index}/_doc/{id}", "{index}/_doc"});
internal static ApiUrls IndicesAnalyze = new ApiUrls(new[]{"_analyze", "{index}/_analyze"});
internal static ApiUrls IndicesClearCache = new ApiUrls(new[]{"_cache/clear", "{index}/_cache/clear"});
internal static ApiUrls IndicesClone = new ApiUrls(new[]{"{index}/_clone/{target}"});
internal static ApiUrls IndicesClose = new ApiUrls(new[]{"{index}/_close"});
internal static ApiUrls IndicesCreate = new ApiUrls(new[]{"{index}"});
internal static ApiUrls IndicesDelete = new ApiUrls(new[]{"{index}"});
Expand Down
Loading

0 comments on commit 92ce48e

Please sign in to comment.