Skip to content

[Backport 7.9] Add indices resolve index API #4906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/ApiGenerator/Configuration/CodeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public static class CodeConfiguration

public static string[] IgnoredApisHighLevel { get; } =
{
"indices.resolve_index.json", // TODO: implement
"security.clear_cached_privileges.json", // TODO: implement

"autoscaling.get_autoscaling_decision.json", // 7.7 experimental
Expand Down
23 changes: 23 additions & 0 deletions src/Nest/Descriptors.Indices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,29 @@ public ReloadSearchAnalyzersDescriptor Index<TOther>()
public ReloadSearchAnalyzersDescriptor IgnoreUnavailable(bool? ignoreunavailable = true) => Qs("ignore_unavailable", ignoreunavailable);
}

///<summary>Descriptor for Resolve <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-resolve-index.html</para></summary>
public partial class ResolveIndexDescriptor : RequestDescriptorBase<ResolveIndexDescriptor, ResolveIndexRequestParameters, IResolveIndexRequest>, IResolveIndexRequest
{
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesResolve;
///<summary>/_resolve/index/{name}</summary>
///<param name = "name">this parameter is required</param>
public ResolveIndexDescriptor(Names name): base(r => r.Required("name", name))
{
}

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

// values part of the url path
Names IResolveIndexRequest.Name => Self.RouteValues.Get<Names>("name");
// Request parameters
///<summary>Whether wildcard expressions should get expanded to open or closed indices (default: open)</summary>
public ResolveIndexDescriptor ExpandWildcards(ExpandWildcards? expandwildcards) => Qs("expand_wildcards", expandwildcards);
}

///<summary>Descriptor for Rollover <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html</para></summary>
public partial class RolloverIndexDescriptor : RequestDescriptorBase<RolloverIndexDescriptor, RolloverIndexRequestParameters, IRolloverIndexRequest>, IRolloverIndexRequest
{
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 @@ -787,6 +787,30 @@ public Task<PutMappingResponse> PutMappingAsync<TDocument>(Func<PutMappingDescri
/// </summary>
public Task<ReloadSearchAnalyzersResponse> ReloadSearchAnalyzersAsync(IReloadSearchAnalyzersRequest request, CancellationToken ct = default) => DoRequestAsync<IReloadSearchAnalyzersRequest, ReloadSearchAnalyzersResponse>(request, request.RequestParameters, ct);
/// <summary>
/// <c>GET</c> request to the <c>indices.resolve_index</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-resolve-index.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-resolve-index.html</a>
/// </summary>
public ResolveIndexResponse Resolve(Names name, Func<ResolveIndexDescriptor, IResolveIndexRequest> selector = null) => Resolve(selector.InvokeOrDefault(new ResolveIndexDescriptor(name: name)));
/// <summary>
/// <c>GET</c> request to the <c>indices.resolve_index</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-resolve-index.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-resolve-index.html</a>
/// </summary>
public Task<ResolveIndexResponse> ResolveAsync(Names name, Func<ResolveIndexDescriptor, IResolveIndexRequest> selector = null, CancellationToken ct = default) => ResolveAsync(selector.InvokeOrDefault(new ResolveIndexDescriptor(name: name)), ct);
/// <summary>
/// <c>GET</c> request to the <c>indices.resolve_index</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-resolve-index.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-resolve-index.html</a>
/// </summary>
public ResolveIndexResponse Resolve(IResolveIndexRequest request) => DoRequest<IResolveIndexRequest, ResolveIndexResponse>(request, request.RequestParameters);
/// <summary>
/// <c>GET</c> request to the <c>indices.resolve_index</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-resolve-index.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-resolve-index.html</a>
/// </summary>
public Task<ResolveIndexResponse> ResolveAsync(IResolveIndexRequest request, CancellationToken ct = default) => DoRequestAsync<IResolveIndexRequest, ResolveIndexResponse>(request, request.RequestParameters, ct);
/// <summary>
/// <c>POST</c> request to the <c>indices.rollover</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Nest
{
/// <summary>
/// A request to the resolve index API
/// </summary>
[MapsApi("indices.resolve_index.json")]
[ReadAs(typeof(ResolveIndexRequest))]
public partial interface IResolveIndexRequest
{
}

/// <inheritdoc cref="IResolveIndexRequest" />
public partial class ResolveIndexRequest
{
}

/// <inheritdoc cref="IResolveIndexRequest" />
public partial class ResolveIndexDescriptor
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Collections.Generic;
using System.Runtime.Serialization;
using Elasticsearch.Net;

namespace Nest
{
public class ResolveIndexResponse : ResponseBase
{
[DataMember(Name = "indices")]
public IReadOnlyCollection<ResolvedIndex> Indices { get; internal set; } = EmptyReadOnly<ResolvedIndex>.Collection;

[DataMember(Name = "aliases")]
public IReadOnlyCollection<ResolvedAlias> Aliases { get; internal set; } = EmptyReadOnly<ResolvedAlias>.Collection;

[DataMember(Name = "data_streams")]
public IReadOnlyCollection<ResolvedDataStream> DataStreams { get; internal set; } = EmptyReadOnly<ResolvedDataStream>.Collection;
}

public class ResolvedIndex
{
[DataMember(Name = "name")]
public string Name { get; internal set; }

[DataMember(Name = "aliases")]
public IReadOnlyCollection<string> Aliases { get; internal set; }

[DataMember(Name = "attributes")]
public IReadOnlyCollection<string> Attributes { get; internal set; }

[DataMember(Name = "data_stream")]
public string DataStream { get; internal set; }
}

public class ResolvedAlias
{
[DataMember(Name = "name")]
public string Name { get; internal set; }

[DataMember(Name = "indices")]
public IReadOnlyCollection<string> Indices { get; internal set; }
}

public class ResolvedDataStream
{
[DataMember(Name = "name")]
public string Name { get; internal set; }

[DataMember(Name = "backing_indices")]
public IReadOnlyCollection<string> BackingIndices { get; internal set; }

[DataMember(Name = "timestamp_field")]
public string TimestampField { get; internal set; }
}
}
40 changes: 40 additions & 0 deletions src/Nest/Requests.Indices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,46 @@ public bool? IgnoreUnavailable
}
}

[InterfaceDataContract]
public partial interface IResolveIndexRequest : IRequest<ResolveIndexRequestParameters>
{
[IgnoreDataMember]
Names Name
{
get;
}
}

///<summary>Request for Resolve <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-resolve-index.html</para></summary>
///<remarks>Note: Experimental within the Elasticsearch server, this functionality is experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.</remarks>
public partial class ResolveIndexRequest : PlainRequestBase<ResolveIndexRequestParameters>, IResolveIndexRequest
{
protected IResolveIndexRequest Self => this;
internal override ApiUrls ApiUrls => ApiUrlsLookups.IndicesResolve;
///<summary>/_resolve/index/{name}</summary>
///<param name = "name">this parameter is required</param>
public ResolveIndexRequest(Names name): base(r => r.Required("name", name))
{
}

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

// values part of the url path
[IgnoreDataMember]
Names IResolveIndexRequest.Name => Self.RouteValues.Get<Names>("name");
// Request parameters
///<summary>Whether wildcard expressions should get expanded to open or closed indices (default: open)</summary>
public ExpandWildcards? ExpandWildcards
{
get => Q<ExpandWildcards? >("expand_wildcards");
set => Q("expand_wildcards", value);
}
}

[InterfaceDataContract]
public partial interface IRolloverIndexRequest : IRequest<RolloverIndexRequestParameters>
{
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 @@ -136,6 +136,7 @@ internal static class ApiUrlsLookups
internal static ApiUrls IndicesRecoveryStatus = new ApiUrls(new[]{"_recovery", "{index}/_recovery"});
internal static ApiUrls IndicesRefresh = new ApiUrls(new[]{"_refresh", "{index}/_refresh"});
internal static ApiUrls IndicesReloadSearchAnalyzers = new ApiUrls(new[]{"{index}/_reload_search_analyzers"});
internal static ApiUrls IndicesResolve = new ApiUrls(new[]{"_resolve/index/{name}"});
internal static ApiUrls IndicesRollover = new ApiUrls(new[]{"{alias}/_rollover", "{alias}/_rollover/{new_index}"});
internal static ApiUrls IndicesSegments = new ApiUrls(new[]{"_segments", "{index}/_segments"});
internal static ApiUrls IndicesShardStores = new ApiUrls(new[]{"_shard_stores", "{index}/_shard_stores"});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System;
using System.Collections.Generic;
using System.Linq;
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Tests.Core.Extensions;
using Tests.Core.ManagedElasticsearch.Clusters;
using Tests.Framework.EndpointTests;
using Tests.Framework.EndpointTests.TestState;

namespace Tests.Indices.IndexManagement.ResolveIndex
{
[SkipVersion("<7.9.0", "resolve index introduced in 7.9.0")]
public class ResolveIndexApiTests
: ApiIntegrationTestBase<WritableCluster, ResolveIndexResponse, IResolveIndexRequest, ResolveIndexDescriptor, ResolveIndexRequest>
{
public ResolveIndexApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
{
foreach (var value in values)
{
var createIndexResponse = client.Indices.Create(value.Value, c => c
.Settings(s => s
.NumberOfShards(1)
.NumberOfReplicas(0)
)
.Aliases(a => a
.Alias(value.Value + "-alias")
)
);

if (!createIndexResponse.IsValid)
throw new Exception($"exception whilst setting up integration test: {createIndexResponse.DebugInformation}");

var clusterResponse = client.Cluster.Health(value.Value, c => c.WaitForStatus(WaitForStatus.Green));

if (!clusterResponse.IsValid)
throw new Exception($"exception whilst setting up integration test: {clusterResponse.DebugInformation}");
}
}

protected override bool ExpectIsValid => true;

protected override int ExpectStatusCode => 200;

protected override Func<ResolveIndexDescriptor, IResolveIndexRequest> Fluent => d => d;

protected override HttpMethod HttpMethod => HttpMethod.GET;

protected override ResolveIndexRequest Initializer => new ResolveIndexRequest($"{CallIsolatedValue}*");

protected override string UrlPath => $"/_resolve/index/{CallIsolatedValue}%2A";

protected override LazyResponses ClientUsage() => Calls(
(client, f) => client.Indices.Resolve($"{CallIsolatedValue}*", f),
(client, f) => client.Indices.ResolveAsync($"{CallIsolatedValue}*", f),
(client, r) => client.Indices.Resolve(r),
(client, r) => client.Indices.ResolveAsync(r)
);

protected override ResolveIndexDescriptor NewDescriptor() => new ResolveIndexDescriptor($"{CallIsolatedValue}*");

protected override void ExpectResponse(ResolveIndexResponse response)
{
response.ShouldBeValid();
response.Indices.Should().HaveCount(1);
var resolvedIndex = response.Indices.First();
resolvedIndex.Name.Should().Be(CallIsolatedValue);
resolvedIndex.Aliases.Should().Contain(CallIsolatedValue + "-alias");
resolvedIndex.Attributes.Should().Contain("open");
var resolvedAlias = response.Aliases.First();
resolvedAlias.Name.Should().Be(CallIsolatedValue + "-alias");
resolvedAlias.Indices.Should().Contain(CallIsolatedValue);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Threading.Tasks;
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
using Nest;
using Tests.Framework.EndpointTests;
using static Tests.Framework.EndpointTests.UrlTester;

namespace Tests.Indices.IndexManagement.ResolveIndex
{
public class ResolveIndexUrlTests
{
[U] public async Task Urls()
{
var index = "index1";
await GET($"/_resolve/index/{index}")
.Fluent(c => c.Indices.Resolve(index))
.Request(c => c.Indices.Resolve(new ResolveIndexRequest(index)))
.FluentAsync(c => c.Indices.ResolveAsync(index))
.RequestAsync(c => c.Indices.ResolveAsync(new ResolveIndexRequest(index)))
;
}
}
}