diff --git a/src/ApiGenerator/last_downloaded_version.txt b/src/ApiGenerator/last_downloaded_version.txt index 23da83b8f43..b6445f0c6f7 100644 --- a/src/ApiGenerator/last_downloaded_version.txt +++ b/src/ApiGenerator/last_downloaded_version.txt @@ -1 +1 @@ -7b8637e3a680af6a3930b2e2fc9f4f1f121bd797 \ No newline at end of file +fb84b6710d5ee62c00f51cd041d7318691195fc3 \ No newline at end of file diff --git a/src/Nest/Descriptors.NoNamespace.cs b/src/Nest/Descriptors.NoNamespace.cs index 470bea62bfe..7e9c256de8b 100644 --- a/src/Nest/Descriptors.NoNamespace.cs +++ b/src/Nest/Descriptors.NoNamespace.cs @@ -102,6 +102,14 @@ public partial class ClearScrollDescriptor : RequestDescriptorBaseDescriptor for ClosePointInTime https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + public partial class ClosePointInTimeDescriptor : RequestDescriptorBase, IClosePointInTimeRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceClosePointInTime; + // values part of the url path + // Request parameters + } + ///Descriptor for Count https://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html public partial class CountDescriptor : RequestDescriptorBase, CountRequestParameters, ICountRequest>, ICountRequest { @@ -1099,6 +1107,49 @@ public MultiTermVectorsDescriptor Fields(params Expression>[] public MultiTermVectorsDescriptor VersionType(VersionType? versiontype) => Qs("version_type", versiontype); } + ///Descriptor for OpenPointInTime https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + public partial class OpenPointInTimeDescriptor : RequestDescriptorBase, IOpenPointInTimeRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceOpenPointInTime; + ////_pit + public OpenPointInTimeDescriptor(): base() + { + } + + ////{index}/_pit + ///Optional, accepts null + public OpenPointInTimeDescriptor(Indices index): base(r => r.Optional("index", index)) + { + } + + // values part of the url path + Indices IOpenPointInTimeRequest.Index => Self.RouteValues.Get("index"); + ///A comma-separated list of index names to open point in time; use the special string `_all` or Indices.All to perform the operation on all indices + public OpenPointInTimeDescriptor Index(Indices index) => Assign(index, (a, v) => a.RouteValues.Optional("index", v)); + ///a shortcut into calling Index(typeof(TOther)) + public OpenPointInTimeDescriptor Index() + where TOther : class => Assign(typeof(TOther), (a, v) => a.RouteValues.Optional("index", (Indices)v)); + ///A shortcut into calling Index(Indices.All) + public OpenPointInTimeDescriptor AllIndices() => Index(Indices.All); + // Request parameters + ///Whether to expand wildcard expression to concrete indices that are open, closed or both. + public OpenPointInTimeDescriptor ExpandWildcards(ExpandWildcards? expandwildcards) => Qs("expand_wildcards", expandwildcards); + ///Whether specified concrete indices should be ignored when unavailable (missing or closed) + public OpenPointInTimeDescriptor IgnoreUnavailable(bool? ignoreunavailable = true) => Qs("ignore_unavailable", ignoreunavailable); + ///Specific the time to live for the point in time + public OpenPointInTimeDescriptor KeepAlive(string keepalive) => Qs("keep_alive", keepalive); + ///Specify the node or shard the operation should be performed on (default: random) + public OpenPointInTimeDescriptor Preference(string preference) => Qs("preference", preference); + /// + /// A document is routed to a particular shard in an index using the following formula + /// shard_num = hash(_routing) % num_primary_shards + /// Elasticsearch will use the document id if not provided. + /// For requests that are constructed from/for a document NEST will automatically infer the routing key + /// if that document has a or a routing mapping on for its type exists on + /// + public OpenPointInTimeDescriptor Routing(Routing routing) => Qs("routing", routing); + } + ///Descriptor for Ping https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html public partial class PingDescriptor : RequestDescriptorBase, IPingRequest { diff --git a/src/Nest/ElasticClient.NoNamespace.cs b/src/Nest/ElasticClient.NoNamespace.cs index c853afe6766..dccc4dcdb81 100644 --- a/src/Nest/ElasticClient.NoNamespace.cs +++ b/src/Nest/ElasticClient.NoNamespace.cs @@ -288,6 +288,30 @@ partial void SetupNamespaces() /// public Task ClearScrollAsync(IClearScrollRequest request, CancellationToken ct = default) => DoRequestAsync(request, request.RequestParameters, ct); /// + /// DELETE request to the close_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + public ClosePointInTimeResponse ClosePointInTime(Func selector = null) => ClosePointInTime(selector.InvokeOrDefault(new ClosePointInTimeDescriptor())); + /// + /// DELETE request to the close_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + public Task ClosePointInTimeAsync(Func selector = null, CancellationToken ct = default) => ClosePointInTimeAsync(selector.InvokeOrDefault(new ClosePointInTimeDescriptor()), ct); + /// + /// DELETE request to the close_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + public ClosePointInTimeResponse ClosePointInTime(IClosePointInTimeRequest request) => DoRequest(request, request.RequestParameters); + /// + /// DELETE request to the close_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + public Task ClosePointInTimeAsync(IClosePointInTimeRequest request, CancellationToken ct = default) => DoRequestAsync(request, request.RequestParameters, ct); + /// /// POST request to the count API, read more about this API online: /// /// https://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html @@ -774,6 +798,30 @@ public Task IndexAsync(IIndexRequest reques /// public Task MultiTermVectorsAsync(IMultiTermVectorsRequest request, CancellationToken ct = default) => DoRequestAsync(request, request.RequestParameters, ct); /// + /// POST request to the open_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + public OpenPointInTimeResponse OpenPointInTime(Indices index = null, Func selector = null) => OpenPointInTime(selector.InvokeOrDefault(new OpenPointInTimeDescriptor().Index(index: index))); + /// + /// POST request to the open_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + public Task OpenPointInTimeAsync(Indices index = null, Func selector = null, CancellationToken ct = default) => OpenPointInTimeAsync(selector.InvokeOrDefault(new OpenPointInTimeDescriptor().Index(index: index)), ct); + /// + /// POST request to the open_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + public OpenPointInTimeResponse OpenPointInTime(IOpenPointInTimeRequest request) => DoRequest(request, request.RequestParameters); + /// + /// POST request to the open_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + public Task OpenPointInTimeAsync(IOpenPointInTimeRequest request, CancellationToken ct = default) => DoRequestAsync(request, request.RequestParameters, ct); + /// /// HEAD request to the ping API, read more about this API online: /// /// https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html diff --git a/src/Nest/IElasticClient.Generated.cs b/src/Nest/IElasticClient.Generated.cs index 398903b248f..c189f241b6c 100644 --- a/src/Nest/IElasticClient.Generated.cs +++ b/src/Nest/IElasticClient.Generated.cs @@ -185,6 +185,30 @@ NodesNamespace Nodes /// Task ClearScrollAsync(IClearScrollRequest request, CancellationToken ct = default); /// + /// DELETE request to the close_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + ClosePointInTimeResponse ClosePointInTime(Func selector = null); + /// + /// DELETE request to the close_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + Task ClosePointInTimeAsync(Func selector = null, CancellationToken ct = default); + /// + /// DELETE request to the close_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + ClosePointInTimeResponse ClosePointInTime(IClosePointInTimeRequest request); + /// + /// DELETE request to the close_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + Task ClosePointInTimeAsync(IClosePointInTimeRequest request, CancellationToken ct = default); + /// /// POST request to the count API, read more about this API online: /// /// https://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html @@ -671,6 +695,30 @@ Task IndexAsync(IIndexRequest request, Canc /// Task MultiTermVectorsAsync(IMultiTermVectorsRequest request, CancellationToken ct = default); /// + /// POST request to the open_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + OpenPointInTimeResponse OpenPointInTime(Indices index = null, Func selector = null); + /// + /// POST request to the open_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + Task OpenPointInTimeAsync(Indices index = null, Func selector = null, CancellationToken ct = default); + /// + /// POST request to the open_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + OpenPointInTimeResponse OpenPointInTime(IOpenPointInTimeRequest request); + /// + /// POST request to the open_point_in_time API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + /// + Task OpenPointInTimeAsync(IOpenPointInTimeRequest request, CancellationToken ct = default); + /// /// HEAD request to the ping API, read more about this API online: /// /// https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html diff --git a/src/Nest/Requests.NoNamespace.cs b/src/Nest/Requests.NoNamespace.cs index a344d06255e..ba8f034086b 100644 --- a/src/Nest/Requests.NoNamespace.cs +++ b/src/Nest/Requests.NoNamespace.cs @@ -167,6 +167,20 @@ public partial class ClearScrollRequest : PlainRequestBase + { + } + + ///Request for ClosePointInTime https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + public partial class ClosePointInTimeRequest : PlainRequestBase, IClosePointInTimeRequest + { + protected IClosePointInTimeRequest Self => this; + internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceClosePointInTime; + // values part of the url path + // Request parameters + } + [InterfaceDataContract] public partial interface ICountRequest : IRequest { @@ -2337,6 +2351,79 @@ public VersionType? VersionType } } + [InterfaceDataContract] + public partial interface IOpenPointInTimeRequest : IRequest + { + [IgnoreDataMember] + Indices Index + { + get; + } + } + + ///Request for OpenPointInTime https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + public partial class OpenPointInTimeRequest : PlainRequestBase, IOpenPointInTimeRequest + { + protected IOpenPointInTimeRequest Self => this; + internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceOpenPointInTime; + ////_pit + public OpenPointInTimeRequest(): base() + { + } + + ////{index}/_pit + ///Optional, accepts null + public OpenPointInTimeRequest(Indices index): base(r => r.Optional("index", index)) + { + } + + // values part of the url path + [IgnoreDataMember] + Indices IOpenPointInTimeRequest.Index => Self.RouteValues.Get("index"); + // Request parameters + ///Whether to expand wildcard expression to concrete indices that are open, closed or both. + public ExpandWildcards? ExpandWildcards + { + get => Q("expand_wildcards"); + set => Q("expand_wildcards", value); + } + + ///Whether specified concrete indices should be ignored when unavailable (missing or closed) + public bool? IgnoreUnavailable + { + get => Q("ignore_unavailable"); + set => Q("ignore_unavailable", value); + } + + ///Specific the time to live for the point in time + public string KeepAlive + { + get => Q("keep_alive"); + set => Q("keep_alive", value); + } + + ///Specify the node or shard the operation should be performed on (default: random) + public string Preference + { + get => Q("preference"); + set => Q("preference", value); + } + + /// + /// A document is routed to a particular shard in an index using the following formula + /// shard_num = hash(_routing) % num_primary_shards + /// Elasticsearch will use the document id if not provided. + /// For requests that are constructed from/for a document NEST will automatically infer the routing key + /// if that document has a or a routing mapping on for its type exists on + /// + public Routing Routing + { + get => Q("routing"); + set => Q("routing", value); + } + } + [InterfaceDataContract] public partial interface IPingRequest : IRequest { diff --git a/src/Nest/Search/Search/PointInTime/Close/ClosePointInTimeRequest.cs b/src/Nest/Search/Search/PointInTime/Close/ClosePointInTimeRequest.cs new file mode 100644 index 00000000000..0d329d832a5 --- /dev/null +++ b/src/Nest/Search/Search/PointInTime/Close/ClosePointInTimeRequest.cs @@ -0,0 +1,33 @@ +// 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.Runtime.Serialization; + +namespace Nest +{ + [MapsApi("close_point_in_time.json")] + public partial interface IClosePointInTimeRequest + { + /// + /// The ID of the point in time to close. + /// + [DataMember(Name = "id")] + string Id { get; set; } + } + + /// + public partial class ClosePointInTimeRequest + { + /// + public string Id { get; set; } + } + + public partial class ClosePointInTimeDescriptor + { + string IClosePointInTimeRequest.Id { get; set; } + + /// + public ClosePointInTimeDescriptor Id(string id) => Assign(id, (a, v) => a.Id = v); + } +} diff --git a/src/Nest/Search/Search/PointInTime/Close/ClosePointInTimeResponse.cs b/src/Nest/Search/Search/PointInTime/Close/ClosePointInTimeResponse.cs new file mode 100644 index 00000000000..a810100b994 --- /dev/null +++ b/src/Nest/Search/Search/PointInTime/Close/ClosePointInTimeResponse.cs @@ -0,0 +1,23 @@ +// 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.Runtime.Serialization; + +namespace Nest +{ + public class ClosePointInTimeResponse : ResponseBase + { + /// + /// If true, all search contexts associated with the point-in-time id are successfully closed. + /// + [DataMember(Name = "succeeded")] + public bool Succeeded { get; internal set; } + + /// + /// The number of search contexts have been successfully closed. + /// + [DataMember(Name = "num_freed")] + public int NumberFreed { get; internal set; } + } +} diff --git a/src/Nest/Search/Search/PointInTime/Open/OpenPointInTimeRequest.cs b/src/Nest/Search/Search/PointInTime/Open/OpenPointInTimeRequest.cs new file mode 100644 index 00000000000..2763edf16e7 --- /dev/null +++ b/src/Nest/Search/Search/PointInTime/Open/OpenPointInTimeRequest.cs @@ -0,0 +1,13 @@ +// 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 +{ + [MapsApi("open_point_in_time.json")] + public partial interface IOpenPointInTimeRequest { } + + public partial class OpenPointInTimeRequest { } + + public partial class OpenPointInTimeDescriptor { } +} diff --git a/src/Nest/Search/Search/PointInTime/Open/OpenPointInTimeResponse.cs b/src/Nest/Search/Search/PointInTime/Open/OpenPointInTimeResponse.cs new file mode 100644 index 00000000000..a07ac77d874 --- /dev/null +++ b/src/Nest/Search/Search/PointInTime/Open/OpenPointInTimeResponse.cs @@ -0,0 +1,14 @@ +// 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.Runtime.Serialization; + +namespace Nest +{ + public class OpenPointInTimeResponse : ResponseBase + { + [DataMember(Name = "id")] + public string Id { get; internal set; } + } +} diff --git a/src/Nest/_Generated/ApiUrlsLookup.generated.cs b/src/Nest/_Generated/ApiUrlsLookup.generated.cs index abe4e01f7f4..b01f6e4e68c 100644 --- a/src/Nest/_Generated/ApiUrlsLookup.generated.cs +++ b/src/Nest/_Generated/ApiUrlsLookup.generated.cs @@ -61,6 +61,7 @@ internal static class ApiUrlsLookups internal static ApiUrls CrossClusterReplicationStats = new ApiUrls(new[]{"_ccr/stats"}); internal static ApiUrls CrossClusterReplicationUnfollowIndex = new ApiUrls(new[]{"{index}/_ccr/unfollow"}); internal static ApiUrls NoNamespaceClearScroll = new ApiUrls(new[]{"_search/scroll"}); + internal static ApiUrls NoNamespaceClosePointInTime = new ApiUrls(new[]{"_pit"}); internal static ApiUrls ClusterAllocationExplain = new ApiUrls(new[]{"_cluster/allocation/explain"}); internal static ApiUrls ClusterDeleteVotingConfigExclusions = new ApiUrls(new[]{"_cluster/voting_config_exclusions"}); internal static ApiUrls ClusterGetSettings = new ApiUrls(new[]{"_cluster/settings"}); @@ -217,6 +218,7 @@ internal static class ApiUrlsLookups internal static ApiUrls NodesReloadSecureSettings = new ApiUrls(new[]{"_nodes/reload_secure_settings", "_nodes/{node_id}/reload_secure_settings"}); internal static ApiUrls NodesStats = new ApiUrls(new[]{"_nodes/stats", "_nodes/{node_id}/stats", "_nodes/stats/{metric}", "_nodes/{node_id}/stats/{metric}", "_nodes/stats/{metric}/{index_metric}", "_nodes/{node_id}/stats/{metric}/{index_metric}"}); internal static ApiUrls NodesUsage = new ApiUrls(new[]{"_nodes/usage", "_nodes/{node_id}/usage", "_nodes/usage/{metric}", "_nodes/{node_id}/usage/{metric}"}); + internal static ApiUrls NoNamespaceOpenPointInTime = new ApiUrls(new[]{"_pit", "{index}/_pit"}); internal static ApiUrls NoNamespacePing = new ApiUrls(new[]{""}); internal static ApiUrls NoNamespacePutScript = new ApiUrls(new[]{"_scripts/{id}", "_scripts/{id}/{context}"}); internal static ApiUrls NoNamespaceReindexOnServer = new ApiUrls(new[]{"_reindex"}); diff --git a/tests/Tests/Search/PointInTime/Close/ClosePointInTimeApiTests.cs b/tests/Tests/Search/PointInTime/Close/ClosePointInTimeApiTests.cs new file mode 100644 index 00000000000..0b4d7720e43 --- /dev/null +++ b/tests/Tests/Search/PointInTime/Close/ClosePointInTimeApiTests.cs @@ -0,0 +1,61 @@ +// 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 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.Search.PointInTime.Close +{ + [SkipVersion("<7.10.0", "Api introduced in 7.10.0")] + public class ClosePointInTimeApiTests + : ApiIntegrationTestBase + { + public ClosePointInTimeApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + private const string IdKey = "Id"; + + protected override void OnBeforeCall(IElasticClient client) + { + var pit = client.OpenPointInTime("devs", p => p.KeepAlive("5m")); + pit.ShouldBeValid(); + ExtendedValue(IdKey, pit.Id); + } + + protected override bool ExpectIsValid => true; + + protected override int ExpectStatusCode => 200; + + protected override Func Fluent => c => c + .Id(RanIntegrationSetup ? ExtendedValue(IdKey) : RandomString()); + + protected override HttpMethod HttpMethod => HttpMethod.DELETE; + + protected override ClosePointInTimeRequest Initializer => new() + { + Id = RanIntegrationSetup ? ExtendedValue(IdKey) : RandomString() + }; + + protected override string UrlPath => "/_pit"; + + protected override LazyResponses ClientUsage() => Calls( + (c, f) => c.ClosePointInTime(f), + (c, f) => c.ClosePointInTimeAsync(f), + (c, r) => c.ClosePointInTime(r), + (c, r) => c.ClosePointInTimeAsync(r) + ); + + protected override void ExpectResponse(ClosePointInTimeResponse response) + { + response.Succeeded.Should().BeTrue(); + response.NumberFreed.Should().BeGreaterOrEqualTo(1); + } + } +} diff --git a/tests/Tests/Search/PointInTime/Close/ClosePointInTimeUrlTests.cs b/tests/Tests/Search/PointInTime/Close/ClosePointInTimeUrlTests.cs new file mode 100644 index 00000000000..10735d9aaac --- /dev/null +++ b/tests/Tests/Search/PointInTime/Close/ClosePointInTimeUrlTests.cs @@ -0,0 +1,22 @@ +// 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.Search.PointInTime.Close +{ + public class ClosePointInTimeUrlTests + { + [U] public async Task Urls() => + await DELETE("/_pit") + .Fluent(c => c.ClosePointInTime()) + .Request(c => c.ClosePointInTime(new ClosePointInTimeRequest())) + .FluentAsync(c => c.ClosePointInTimeAsync()) + .RequestAsync(c => c.ClosePointInTimeAsync(new ClosePointInTimeRequest())); + } +} diff --git a/tests/Tests/Search/PointInTime/Open/OpenPointInTimeApiTests.cs b/tests/Tests/Search/PointInTime/Open/OpenPointInTimeApiTests.cs new file mode 100644 index 00000000000..09718b9cac8 --- /dev/null +++ b/tests/Tests/Search/PointInTime/Open/OpenPointInTimeApiTests.cs @@ -0,0 +1,49 @@ +// 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 Elastic.Elasticsearch.Xunit.XunitPlumbing; +using Elasticsearch.Net; +using FluentAssertions; +using Nest; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Framework.EndpointTests; +using Tests.Framework.EndpointTests.TestState; + +namespace Tests.Search.PointInTime.Open +{ + [SkipVersion("<7.10.0", "Api introduced in 7.10.0")] + public class OpenPointInTimeApiTests + : ApiIntegrationTestBase + { + public OpenPointInTimeApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + protected override bool ExpectIsValid => true; + + protected override int ExpectStatusCode => 200; + + protected override Func Fluent => c => c + .Index("devs") + .KeepAlive("1m"); + + protected override HttpMethod HttpMethod => HttpMethod.POST; + + protected override OpenPointInTimeRequest Initializer => new("devs") + { + KeepAlive = "1m" + }; + + protected override string UrlPath => "/devs/_pit?keep_alive=1m"; + + protected override LazyResponses ClientUsage() => Calls( + (c, f) => c.OpenPointInTime(selector: f), + (c, f) => c.OpenPointInTimeAsync(selector: f), + (c, r) => c.OpenPointInTime(r), + (c, r) => c.OpenPointInTimeAsync(r) + ); + + protected override void ExpectResponse(OpenPointInTimeResponse response) => + response.Id.Should().NotBeNullOrEmpty(); + } +} diff --git a/tests/Tests/Search/PointInTime/Open/OpenPointInTimeUrlTests.cs b/tests/Tests/Search/PointInTime/Open/OpenPointInTimeUrlTests.cs new file mode 100644 index 00000000000..67b72f4dc45 --- /dev/null +++ b/tests/Tests/Search/PointInTime/Open/OpenPointInTimeUrlTests.cs @@ -0,0 +1,32 @@ +// 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.Search.PointInTime.Open +{ + public class OpenPointInTimeUrlTests + { + [U] public async Task Urls() + { + await POST("/_pit") + .Fluent(c => c.OpenPointInTime()) + .Request(c => c.OpenPointInTime(new OpenPointInTimeRequest())) + .FluentAsync(c => c.OpenPointInTimeAsync()) + .RequestAsync(c => c.OpenPointInTimeAsync(new OpenPointInTimeRequest())); + + const string index = "devs"; + + await POST($"/{index}/_pit") + .Fluent(c => c.OpenPointInTime(index)) + .Request(c => c.OpenPointInTime(new OpenPointInTimeRequest(index))) + .FluentAsync(c => c.OpenPointInTimeAsync(index)) + .RequestAsync(c => c.OpenPointInTimeAsync(new OpenPointInTimeRequest(index))); + } + } +}