From 63cb9b62e69c40e49d7b67d328f932dc5a5c4d41 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 4 May 2021 09:44:16 +0100 Subject: [PATCH 1/4] Add NEST support for EQL search status API (#5663) * Add initial request and response * Generate code for EQL get status * Add test, update naming and headers * Update models and assertions (cherry picked from commit 4dec45f93ff356d7c3df07082976947848bf1ca1) --- .../RequestParameters.Eql.cs | 4 +- .../ElasticLowLevelClient.Eql.cs | 8 +- src/Nest/Descriptors.Eql.cs | 21 +++++ src/Nest/ElasticClient.Eql.cs | 24 +++++ src/Nest/Requests.Eql.cs | 33 +++++++ .../XPack/Eql/Search/EqlSearchResponse.cs | 10 +- .../Eql/Status/EqlSearchStatusRequest.cs | 29 ++++++ .../Eql/Status/EqlSearchStatusResponse.cs | 65 +++++++++++++ .../_Generated/ApiUrlsLookup.generated.cs | 1 + tests/Tests.Configuration/tests.default.yaml | 4 +- .../XPack/Eql/EqlSearchApiCoordinatedTests.cs | 93 +++++++++++++++++++ .../Eql/Status/EqlSearchStatusUrlTests.cs | 36 +++++++ 12 files changed, 315 insertions(+), 13 deletions(-) create mode 100644 src/Nest/XPack/Eql/Status/EqlSearchStatusRequest.cs create mode 100644 src/Nest/XPack/Eql/Status/EqlSearchStatusResponse.cs create mode 100644 tests/Tests/XPack/Eql/EqlSearchApiCoordinatedTests.cs create mode 100644 tests/Tests/XPack/Eql/Status/EqlSearchStatusUrlTests.cs diff --git a/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Eql.cs b/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Eql.cs index fbad22711fc..06b3421b49e 100644 --- a/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Eql.cs +++ b/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Eql.cs @@ -66,8 +66,8 @@ public TimeSpan WaitForCompletionTimeout } } - ///Request options for GetStatus https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html - public class GetStatusRequestParameters : RequestParameters + ///Request options for SearchStatus https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + public class EqlSearchStatusRequestParameters : RequestParameters { } diff --git a/src/Elasticsearch.Net/ElasticLowLevelClient.Eql.cs b/src/Elasticsearch.Net/ElasticLowLevelClient.Eql.cs index 124f1baeed8..76a4aae8ae3 100644 --- a/src/Elasticsearch.Net/ElasticLowLevelClient.Eql.cs +++ b/src/Elasticsearch.Net/ElasticLowLevelClient.Eql.cs @@ -87,14 +87,14 @@ public Task GetAsync(string id, GetRequestParameters reque ///GET on /_eql/search/status/{id} https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html ///The async search ID ///Request specific configuration such as querystring parameters & request specific connection settings. - public TResponse GetStatus(string id, GetStatusRequestParameters requestParameters = null) - where TResponse : class, ITransportResponse, new() => DoRequest(GET, Url($"_eql/search/status/{id:id}"), null, RequestParams(requestParameters)); + public TResponse SearchStatus(string id, EqlSearchStatusRequestParameters requestParameters = null) + where TResponse : class, IElasticsearchResponse, new() => DoRequest(GET, Url($"_eql/search/status/{id:id}"), null, RequestParams(requestParameters)); ///GET on /_eql/search/status/{id} https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html ///The async search ID ///Request specific configuration such as querystring parameters & request specific connection settings. [MapsApi("eql.get_status", "id")] - public Task GetStatusAsync(string id, GetStatusRequestParameters requestParameters = null, CancellationToken ctx = default) - where TResponse : class, ITransportResponse, new() => DoRequestAsync(GET, Url($"_eql/search/status/{id:id}"), ctx, null, RequestParams(requestParameters)); + public Task SearchStatusAsync(string id, EqlSearchStatusRequestParameters requestParameters = null, CancellationToken ctx = default) + where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync(GET, Url($"_eql/search/status/{id:id}"), ctx, null, RequestParams(requestParameters)); ///POST on /{index}/_eql/search https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html ///A comma-separated list of index names to search; use the special string `_all` or Indices.All to perform the operation on all indices ///Eql request body. Use the `query` to limit the query scope. diff --git a/src/Nest/Descriptors.Eql.cs b/src/Nest/Descriptors.Eql.cs index 0a15c620deb..a431e459866 100644 --- a/src/Nest/Descriptors.Eql.cs +++ b/src/Nest/Descriptors.Eql.cs @@ -49,6 +49,27 @@ // ReSharper disable RedundantNameQualifier namespace Nest { + ///Descriptor for SearchStatus https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + public partial class EqlSearchStatusDescriptor : RequestDescriptorBase, IEqlSearchStatusRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.EqlSearchStatus; + ////_eql/search/status/{id} + ///this parameter is required + public EqlSearchStatusDescriptor(Id id): base(r => r.Required("id", id)) + { + } + + ///Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected EqlSearchStatusDescriptor(): base() + { + } + + // values part of the url path + Id IEqlSearchStatusRequest.Id => Self.RouteValues.Get("id"); + // Request parameters + } + ///Descriptor for Search https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html public partial class EqlSearchDescriptor : RequestDescriptorBase, EqlSearchRequestParameters, IEqlSearchRequest>, IEqlSearchRequest { diff --git a/src/Nest/ElasticClient.Eql.cs b/src/Nest/ElasticClient.Eql.cs index 23c5b658e65..e18fb769e93 100644 --- a/src/Nest/ElasticClient.Eql.cs +++ b/src/Nest/ElasticClient.Eql.cs @@ -54,6 +54,30 @@ internal EqlNamespace(ElasticClient client): base(client) { } + /// + /// GET request to the eql.get_status API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + /// + public EqlSearchStatusResponse SearchStatus(Id id, Func selector = null) => SearchStatus(selector.InvokeOrDefault(new EqlSearchStatusDescriptor(id: id))); + /// + /// GET request to the eql.get_status API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + /// + public Task SearchStatusAsync(Id id, Func selector = null, CancellationToken ct = default) => SearchStatusAsync(selector.InvokeOrDefault(new EqlSearchStatusDescriptor(id: id)), ct); + /// + /// GET request to the eql.get_status API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + /// + public EqlSearchStatusResponse SearchStatus(IEqlSearchStatusRequest request) => DoRequest(request, request.RequestParameters); + /// + /// GET request to the eql.get_status API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + /// + public Task SearchStatusAsync(IEqlSearchStatusRequest request, CancellationToken ct = default) => DoRequestAsync(request, request.RequestParameters, ct); /// /// POST request to the eql.search API, read more about this API online: /// diff --git a/src/Nest/Requests.Eql.cs b/src/Nest/Requests.Eql.cs index 1143f1dc1b6..4c62d729d1d 100644 --- a/src/Nest/Requests.Eql.cs +++ b/src/Nest/Requests.Eql.cs @@ -50,6 +50,39 @@ // ReSharper disable RedundantNameQualifier namespace Nest { + [InterfaceDataContract] + public partial interface IEqlSearchStatusRequest : IRequest + { + [IgnoreDataMember] + Id Id + { + get; + } + } + + ///Request for SearchStatus https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + public partial class EqlSearchStatusRequest : PlainRequestBase, IEqlSearchStatusRequest + { + protected IEqlSearchStatusRequest Self => this; + internal override ApiUrls ApiUrls => ApiUrlsLookups.EqlSearchStatus; + ////_eql/search/status/{id} + ///this parameter is required + public EqlSearchStatusRequest(Id id): base(r => r.Required("id", id)) + { + } + + ///Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected EqlSearchStatusRequest(): base() + { + } + + // values part of the url path + [IgnoreDataMember] + Id IEqlSearchStatusRequest.Id => Self.RouteValues.Get("id"); + // Request parameters + } + [InterfaceDataContract] public partial interface IEqlSearchRequest : IRequest { diff --git a/src/Nest/XPack/Eql/Search/EqlSearchResponse.cs b/src/Nest/XPack/Eql/Search/EqlSearchResponse.cs index 607d2aabad7..b9a8b587aa1 100644 --- a/src/Nest/XPack/Eql/Search/EqlSearchResponse.cs +++ b/src/Nest/XPack/Eql/Search/EqlSearchResponse.cs @@ -59,31 +59,31 @@ public class EqlSearchResponse : ResponseBase where TDocument : class /// Identifier for the search. /// [DataMember(Name = "id")] - public Id Id { get; internal set; } + public string Id { get; internal set; } /// /// If true, the response does not contain complete search results. /// [DataMember(Name = "is_partial")] - public bool? IsPartial { get; internal set; } + public bool IsPartial { get; internal set; } /// /// If true, the search request is still executing. /// [DataMember(Name = "is_running")] - public bool? IsRunning { get; internal set; } + public bool IsRunning { get; internal set; } /// /// Milliseconds it took Elasticsearch to execute the request. /// [DataMember(Name = "took")] - public int Took { get; internal set; } + public long Took { get; internal set; } /// /// If true, the request timed out before completion. /// [DataMember(Name = "timed_out")] - public bool? TimedOut { get; internal set; } + public bool TimedOut { get; internal set; } /// /// The total number of hits. diff --git a/src/Nest/XPack/Eql/Status/EqlSearchStatusRequest.cs b/src/Nest/XPack/Eql/Status/EqlSearchStatusRequest.cs new file mode 100644 index 00000000000..e59f685c738 --- /dev/null +++ b/src/Nest/XPack/Eql/Status/EqlSearchStatusRequest.cs @@ -0,0 +1,29 @@ +/* + * 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 +{ + [MapsApi("eql.get_status.json")] + [ReadAs(typeof(EqlSearchStatusRequest))] + public partial interface IEqlSearchStatusRequest { } + + public partial class EqlSearchStatusRequest { } + + public partial class EqlSearchStatusDescriptor { } +} diff --git a/src/Nest/XPack/Eql/Status/EqlSearchStatusResponse.cs b/src/Nest/XPack/Eql/Status/EqlSearchStatusResponse.cs new file mode 100644 index 00000000000..a8070e42d2e --- /dev/null +++ b/src/Nest/XPack/Eql/Status/EqlSearchStatusResponse.cs @@ -0,0 +1,65 @@ +/* + * 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.Runtime.Serialization; + +namespace Nest +{ + /// + /// A response to an EQL get status request. + /// + public class EqlSearchStatusResponse : ResponseBase + { + /// + /// For a completed search shows the http status code of the completed search. + /// + [DataMember(Name = "completion_status")] + public int CompletionStatus { get; internal set; } + + /// + /// For a running search shows a timestamp when the eql search started, in milliseconds since the Unix epoch. + /// + [DataMember(Name = "expiration_time_in_millis")] + public long ExpirationTimeInMillis { get; internal set; } + + /// + /// Identifier for the search. + /// + [DataMember(Name = "id")] + public string Id { get; internal set; } + + /// + /// If true, the response does not contain complete search results. + /// + [DataMember(Name = "is_partial")] + public bool IsPartial { get; internal set; } + + /// + /// If true, the search request is still executing. If false, the search is completed. + /// + [DataMember(Name = "is_running")] + public bool IsRunning { get; internal set; } + + /// + /// For a running search shows a timestamp when the eql search started, in milliseconds since the Unix epoch. + /// + [DataMember(Name = "start_time_in_millis")] + public long StartTimeInMillis { get; internal set; } + } +} diff --git a/src/Nest/_Generated/ApiUrlsLookup.generated.cs b/src/Nest/_Generated/ApiUrlsLookup.generated.cs index 01a79ff1825..f4a9c825167 100644 --- a/src/Nest/_Generated/ApiUrlsLookup.generated.cs +++ b/src/Nest/_Generated/ApiUrlsLookup.generated.cs @@ -106,6 +106,7 @@ internal static class ApiUrlsLookups internal static ApiUrls EnrichGetPolicy = new ApiUrls(new[]{"_enrich/policy/{name}", "_enrich/policy"}); internal static ApiUrls EnrichPutPolicy = new ApiUrls(new[]{"_enrich/policy/{name}"}); internal static ApiUrls EnrichStats = new ApiUrls(new[]{"_enrich/_stats"}); + internal static ApiUrls EqlSearchStatus = new ApiUrls(new[]{"_eql/search/status/{id}"}); internal static ApiUrls EqlSearch = new ApiUrls(new[]{"{index}/_eql/search"}); internal static ApiUrls NoNamespaceDocumentExists = new ApiUrls(new[]{"{index}/_doc/{id}"}); internal static ApiUrls NoNamespaceSourceExists = new ApiUrls(new[]{"{index}/_source/{id}"}); diff --git a/tests/Tests.Configuration/tests.default.yaml b/tests/Tests.Configuration/tests.default.yaml index 00c6e776d4b..5f545aa877d 100644 --- a/tests/Tests.Configuration/tests.default.yaml +++ b/tests/Tests.Configuration/tests.default.yaml @@ -5,11 +5,11 @@ # tracked by git). # mode either u (unit test), i (integration test) or m (mixed mode) -mode: u +mode: i # the elasticsearch version that should be started # Can be a snapshot version of sonatype or "latest" to get the latest snapshot of sonatype -elasticsearch_version: latest +elasticsearch_version: 7.13.0-SNAPSHOT # cluster filter allows you to only run the integration tests of a particular cluster (cluster suffix not needed) # cluster_filter: # whether we want to forcefully reseed on the node, if you are starting the tests with a node already running diff --git a/tests/Tests/XPack/Eql/EqlSearchApiCoordinatedTests.cs b/tests/Tests/XPack/Eql/EqlSearchApiCoordinatedTests.cs new file mode 100644 index 00000000000..ab9a33bf500 --- /dev/null +++ b/tests/Tests/XPack/Eql/EqlSearchApiCoordinatedTests.cs @@ -0,0 +1,93 @@ +/* + * 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 FluentAssertions; +using Nest; +using Tests.Core.Extensions; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Domain; +using Tests.Framework.EndpointTests; +using Tests.Framework.EndpointTests.TestState; + +namespace Tests.XPack.Eql +{ + [SkipVersion("<7.11.0", "GA in 7.11.0")] + public class EqlSearchApiCoordinatedTests : CoordinatedIntegrationTestBase + { + private const string SubmitStep = nameof(SubmitStep); + private const string StatusStep = nameof(StatusStep); + + public EqlSearchApiCoordinatedTests(TimeSeriesCluster cluster, EndpointUsage usage) : base(new CoordinatedUsage(cluster, usage, testOnlyOne: true) + { + {SubmitStep, u => + u.Calls, EqlSearchRequest, IEqlSearchRequest, EqlSearchResponse>( + v => new EqlSearchRequest + { + Query = "any where true", + KeepOnCompletion = true, + TimestampField = Infer.Field(f => f.Timestamp), + WaitForCompletionTimeout = "1nanos" + }, + (v, d) => d + .Query("any where true") + .KeepOnCompletion() + .TimestampField(Infer.Field(f => f.Timestamp)) + .WaitForCompletionTimeout("1nanos"), + (v, c, f) => c.Eql.Search(f), + (v, c, f) => c.Eql.SearchAsync(f), + (v, c, r) => c.Eql.Search(r), + (v, c, r) => c.Eql.SearchAsync(r), + onResponse: (r, values) => values.ExtendedValue("id", r.Id) + ) + }, + {StatusStep, u => + u.Calls( + v => new EqlSearchStatusRequest(v), + (v, d) => d, + (v, c, f) => c.Eql.SearchStatus(v, f), + (v, c, f) => c.Eql.SearchStatusAsync(v, f), + (v, c, r) => c.Eql.SearchStatus(r), + (v, c, r) => c.Eql.SearchStatusAsync(r), + uniqueValueSelector: values => values.ExtendedValue("id") + ) + } + }) { } + + [I] public async Task EqlSearchResponse() => await Assert>(SubmitStep, r => + { + r.ShouldBeValid(); + r.Id.Should().NotBeNullOrEmpty(); + r.IsPartial.Should().BeTrue(); + r.IsRunning.Should().BeTrue(); + r.TimedOut.Should().BeFalse(); + }); + + [I] public async Task EqlSearchStatusResponse() => await Assert(StatusStep, r => + { + r.ShouldBeValid(); + r.Id.Should().NotBeNullOrEmpty(); + r.IsPartial.Should().BeTrue(); + r.IsRunning.Should().BeTrue(); + r.ExpirationTimeInMillis.Should().BeGreaterThan(0); + r.StartTimeInMillis.Should().BeGreaterThan(0); + }); + } +} diff --git a/tests/Tests/XPack/Eql/Status/EqlSearchStatusUrlTests.cs b/tests/Tests/XPack/Eql/Status/EqlSearchStatusUrlTests.cs new file mode 100644 index 00000000000..ea4d46b8a49 --- /dev/null +++ b/tests/Tests/XPack/Eql/Status/EqlSearchStatusUrlTests.cs @@ -0,0 +1,36 @@ +/* + * 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.Eql.Status +{ + public class EqlSearchStatusUrlTests : UrlTestsBase + { + [U] public override async Task Urls() => await GET("/_eql/search/status/search_id") + .Fluent(c => c.Eql.SearchStatus("search_id", f => f)) + .Request(c => c.Eql.SearchStatus(new EqlSearchStatusRequest("search_id"))) + .FluentAsync(c => c.Eql.SearchStatusAsync("search_id", f => f)) + .RequestAsync(c => c.Eql.SearchStatusAsync(new EqlSearchStatusRequest("search_id"))); + } +} From 2e3ed0fc1073a51581f0f162369e2f37d20a9d14 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 4 May 2021 11:22:32 +0100 Subject: [PATCH 2/4] Add NEST support for EQL Get Search API (#5665) * Add initial request and response * Generate code for EQL get status * Add test, update naming and headers * Add initial types * Generate code * Add tests (cherry picked from commit 3d1a3b2cc217a1c9cc7ee7e7591c7306a3a3d5e8) --- .../RequestParameters.Eql.cs | 2 +- .../ElasticLowLevelClient.Eql.cs | 8 ++-- src/Nest/Descriptors.Eql.cs | 25 ++++++++++ src/Nest/ElasticClient.Eql.cs | 28 +++++++++++ src/Nest/Requests.Eql.cs | 46 +++++++++++++++++++ .../Eql/{Search => }/EqlSearchResponse.cs | 0 src/Nest/XPack/Eql/Get/EqlGetRequest.cs | 29 ++++++++++++ src/Nest/XPack/Eql/Get/EqlGetResponse.cs | 28 +++++++++++ .../_Generated/ApiUrlsLookup.generated.cs | 1 + tests/Tests.Configuration/tests.default.yaml | 4 +- .../XPack/Eql/EqlSearchApiCoordinatedTests.cs | 45 ++++++++++++++++++ tests/Tests/XPack/Eql/Get/EqlGetUrlTests.cs | 37 +++++++++++++++ 12 files changed, 246 insertions(+), 7 deletions(-) rename src/Nest/XPack/Eql/{Search => }/EqlSearchResponse.cs (100%) create mode 100644 src/Nest/XPack/Eql/Get/EqlGetRequest.cs create mode 100644 src/Nest/XPack/Eql/Get/EqlGetResponse.cs create mode 100644 tests/Tests/XPack/Eql/Get/EqlGetUrlTests.cs diff --git a/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Eql.cs b/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Eql.cs index 06b3421b49e..b1160ce353d 100644 --- a/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Eql.cs +++ b/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Eql.cs @@ -49,7 +49,7 @@ public class DeleteRequestParameters : RequestParametersRequest options for Get https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html - public class GetRequestParameters : RequestParameters + public class EqlGetRequestParameters : RequestParameters { ///Update the time interval in which the results (partial or final) for this search will be available public TimeSpan KeepAlive diff --git a/src/Elasticsearch.Net/ElasticLowLevelClient.Eql.cs b/src/Elasticsearch.Net/ElasticLowLevelClient.Eql.cs index 76a4aae8ae3..268290c2356 100644 --- a/src/Elasticsearch.Net/ElasticLowLevelClient.Eql.cs +++ b/src/Elasticsearch.Net/ElasticLowLevelClient.Eql.cs @@ -76,14 +76,14 @@ public Task DeleteAsync(string id, DeleteRequestParameters ///GET on /_eql/search/{id} https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html ///The async search ID ///Request specific configuration such as querystring parameters & request specific connection settings. - public TResponse Get(string id, GetRequestParameters requestParameters = null) - where TResponse : class, ITransportResponse, new() => DoRequest(GET, Url($"_eql/search/{id:id}"), null, RequestParams(requestParameters)); + public TResponse Get(string id, EqlGetRequestParameters requestParameters = null) + where TResponse : class, IElasticsearchResponse, new() => DoRequest(GET, Url($"_eql/search/{id:id}"), null, RequestParams(requestParameters)); ///GET on /_eql/search/{id} https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html ///The async search ID ///Request specific configuration such as querystring parameters & request specific connection settings. [MapsApi("eql.get", "id")] - public Task GetAsync(string id, GetRequestParameters requestParameters = null, CancellationToken ctx = default) - where TResponse : class, ITransportResponse, new() => DoRequestAsync(GET, Url($"_eql/search/{id:id}"), ctx, null, RequestParams(requestParameters)); + public Task GetAsync(string id, EqlGetRequestParameters requestParameters = null, CancellationToken ctx = default) + where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync(GET, Url($"_eql/search/{id:id}"), ctx, null, RequestParams(requestParameters)); ///GET on /_eql/search/status/{id} https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html ///The async search ID ///Request specific configuration such as querystring parameters & request specific connection settings. diff --git a/src/Nest/Descriptors.Eql.cs b/src/Nest/Descriptors.Eql.cs index a431e459866..013e05f78bb 100644 --- a/src/Nest/Descriptors.Eql.cs +++ b/src/Nest/Descriptors.Eql.cs @@ -49,6 +49,31 @@ // ReSharper disable RedundantNameQualifier namespace Nest { + ///Descriptor for Get https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + public partial class EqlGetDescriptor : RequestDescriptorBase, IEqlGetRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.EqlGet; + ////_eql/search/{id} + ///this parameter is required + public EqlGetDescriptor(Id id): base(r => r.Required("id", id)) + { + } + + ///Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected EqlGetDescriptor(): base() + { + } + + // values part of the url path + Id IEqlGetRequest.Id => Self.RouteValues.Get("id"); + // Request parameters + ///Update the time interval in which the results (partial or final) for this search will be available + public EqlGetDescriptor KeepAlive(Time keepalive) => Qs("keep_alive", keepalive); + ///Specify the time that the request should block waiting for the final response + public EqlGetDescriptor WaitForCompletionTimeout(Time waitforcompletiontimeout) => Qs("wait_for_completion_timeout", waitforcompletiontimeout); + } + ///Descriptor for SearchStatus https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html public partial class EqlSearchStatusDescriptor : RequestDescriptorBase, IEqlSearchStatusRequest { diff --git a/src/Nest/ElasticClient.Eql.cs b/src/Nest/ElasticClient.Eql.cs index e18fb769e93..c911ad93ae4 100644 --- a/src/Nest/ElasticClient.Eql.cs +++ b/src/Nest/ElasticClient.Eql.cs @@ -54,6 +54,34 @@ internal EqlNamespace(ElasticClient client): base(client) { } + /// + /// GET request to the eql.get API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + /// + public EqlGetResponse Get(Id id, Func selector = null) + where TDocument : class => Get(selector.InvokeOrDefault(new EqlGetDescriptor(id: id))); + /// + /// GET request to the eql.get API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + /// + public Task> GetAsync(Id id, Func selector = null, CancellationToken ct = default) + where TDocument : class => GetAsync(selector.InvokeOrDefault(new EqlGetDescriptor(id: id)), ct); + /// + /// GET request to the eql.get API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + /// + public EqlGetResponse Get(IEqlGetRequest request) + where TDocument : class => DoRequest>(request, request.RequestParameters); + /// + /// GET request to the eql.get API, read more about this API online: + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + /// + public Task> GetAsync(IEqlGetRequest request, CancellationToken ct = default) + where TDocument : class => DoRequestAsync>(request, request.RequestParameters, ct); /// /// GET request to the eql.get_status API, read more about this API online: /// diff --git a/src/Nest/Requests.Eql.cs b/src/Nest/Requests.Eql.cs index 4c62d729d1d..df9328df4e5 100644 --- a/src/Nest/Requests.Eql.cs +++ b/src/Nest/Requests.Eql.cs @@ -50,6 +50,52 @@ // ReSharper disable RedundantNameQualifier namespace Nest { + [InterfaceDataContract] + public partial interface IEqlGetRequest : IRequest + { + [IgnoreDataMember] + Id Id + { + get; + } + } + + ///Request for Get https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + public partial class EqlGetRequest : PlainRequestBase, IEqlGetRequest + { + protected IEqlGetRequest Self => this; + internal override ApiUrls ApiUrls => ApiUrlsLookups.EqlGet; + ////_eql/search/{id} + ///this parameter is required + public EqlGetRequest(Id id): base(r => r.Required("id", id)) + { + } + + ///Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected EqlGetRequest(): base() + { + } + + // values part of the url path + [IgnoreDataMember] + Id IEqlGetRequest.Id => Self.RouteValues.Get("id"); + // Request parameters + ///Update the time interval in which the results (partial or final) for this search will be available + public Time KeepAlive + { + get => Q