Skip to content

[master] Support get async SQL search API #5864

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 3 commits into from
Jul 13, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class SqlDeleteRequestParameters : RequestParameters<SqlDeleteRequestPara
{
}

///<summary>Request options for GetAsync <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html</para></summary>
public class GetAsyncRequestParameters : RequestParameters<GetAsyncRequestParameters>
///<summary>Request options for Get <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html</para></summary>
public class SqlGetRequestParameters : RequestParameters<SqlGetRequestParameters>
{
///<summary>Separator for CSV results</summary>
public string Delimiter
Expand Down
4 changes: 2 additions & 2 deletions src/Elasticsearch.Net/ElasticLowLevelClient.Sql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ public Task<TResponse> DeleteAsync<TResponse>(string id, SqlDeleteRequestParamet
///<summary>GET on /_sql/async/{id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html</para></summary>
///<param name = "id">The async search ID</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public TResponse GetAsync<TResponse>(string id, GetAsyncRequestParameters requestParameters = null)
public TResponse Get<TResponse>(string id, SqlGetRequestParameters requestParameters = null)
where TResponse : class, ITransportResponse, new() => DoRequest<TResponse>(GET, Url($"_sql/async/{id:id}"), null, RequestParams(requestParameters));
///<summary>GET on /_sql/async/{id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html</para></summary>
///<param name = "id">The async search ID</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
[MapsApi("sql.get_async", "id")]
public Task<TResponse> GetAsyncAsync<TResponse>(string id, GetAsyncRequestParameters requestParameters = null, CancellationToken ctx = default)
public Task<TResponse> GetAsync<TResponse>(string id, SqlGetRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, ITransportResponse, new() => DoRequestAsync<TResponse>(GET, Url($"_sql/async/{id:id}"), ctx, null, RequestParams(requestParameters));
///<summary>GET on /_sql/async/status/{id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-status-api.html</para></summary>
///<param name = "id">The async search ID</param>
Expand Down
31 changes: 31 additions & 0 deletions src/Nest/Descriptors.Sql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,37 @@ protected SqlDeleteDescriptor(): base()
// Request parameters
}

///<summary>Descriptor for Get <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html</para></summary>
public partial class SqlGetDescriptor : RequestDescriptorBase<SqlGetDescriptor, SqlGetRequestParameters, ISqlGetRequest>, ISqlGetRequest
{
internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlGet;
protected override HttpMethod HttpMethod => HttpMethod.GET;
protected override bool SupportsBody => false;
///<summary>/_sql/async/{id}</summary>
///<param name = "id">this parameter is required</param>
public SqlGetDescriptor(Id id): base(r => r.Required("id", id))
{
}

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

// values part of the url path
Id ISqlGetRequest.Id => Self.RouteValues.Get<Id>("id");
// Request parameters
///<summary>Separator for CSV results</summary>
public SqlGetDescriptor Delimiter(string delimiter) => Qs("delimiter", delimiter);
///<summary>Short version of the Accept header, e.g. json, yaml</summary>
public SqlGetDescriptor Format(string format) => Qs("format", format);
///<summary>Retention period for the search and its results</summary>
public SqlGetDescriptor KeepAlive(Time keepalive) => Qs("keep_alive", keepalive);
///<summary>Duration to wait for complete results</summary>
public SqlGetDescriptor WaitForCompletionTimeout(Time waitforcompletiontimeout) => Qs("wait_for_completion_timeout", waitforcompletiontimeout);
}

///<summary>Descriptor for SearchStatus <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-status-api.html</para></summary>
public partial class SqlSearchStatusDescriptor : RequestDescriptorBase<SqlSearchStatusDescriptor, SqlSearchStatusRequestParameters, ISqlSearchStatusRequest>, ISqlSearchStatusRequest
{
Expand Down
24 changes: 24 additions & 0 deletions src/Nest/ElasticClient.Sql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ internal SqlNamespace(ElasticClient client): base(client)
/// </summary>
public Task<SqlDeleteResponse> DeleteAsync(ISqlDeleteRequest request, CancellationToken ct = default) => DoRequestAsync<ISqlDeleteRequest, SqlDeleteResponse>(request, request.RequestParameters, ct);
/// <summary>
/// <c>GET</c> request to the <c>sql.get_async</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html</a>
/// </summary>
public SqlGetResponse Get(Id id, Func<SqlGetDescriptor, ISqlGetRequest> selector = null) => Get(selector.InvokeOrDefault(new SqlGetDescriptor(id: id)));
/// <summary>
/// <c>GET</c> request to the <c>sql.get_async</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html</a>
/// </summary>
public Task<SqlGetResponse> GetAsync(Id id, Func<SqlGetDescriptor, ISqlGetRequest> selector = null, CancellationToken ct = default) => GetAsync(selector.InvokeOrDefault(new SqlGetDescriptor(id: id)), ct);
/// <summary>
/// <c>GET</c> request to the <c>sql.get_async</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html</a>
/// </summary>
public SqlGetResponse Get(ISqlGetRequest request) => DoRequest<ISqlGetRequest, SqlGetResponse>(request, request.RequestParameters);
/// <summary>
/// <c>GET</c> request to the <c>sql.get_async</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html</a>
/// </summary>
public Task<SqlGetResponse> GetAsync(ISqlGetRequest request, CancellationToken ct = default) => DoRequestAsync<ISqlGetRequest, SqlGetResponse>(request, request.RequestParameters, ct);
/// <summary>
/// <c>GET</c> request to the <c>sql.get_async_status</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-status-api.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-status-api.html</a>
Expand Down
62 changes: 62 additions & 0 deletions src/Nest/Requests.Sql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,68 @@ protected SqlDeleteRequest(): base()
// Request parameters
}

[InterfaceDataContract]
public partial interface ISqlGetRequest : IRequest<SqlGetRequestParameters>
{
[IgnoreDataMember]
Id Id
{
get;
}
}

///<summary>Request for Get <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html</para></summary>
public partial class SqlGetRequest : PlainRequestBase<SqlGetRequestParameters>, ISqlGetRequest
{
protected ISqlGetRequest Self => this;
internal override ApiUrls ApiUrls => ApiUrlsLookups.SqlGet;
protected override HttpMethod HttpMethod => HttpMethod.GET;
protected override bool SupportsBody => false;
///<summary>/_sql/async/{id}</summary>
///<param name = "id">this parameter is required</param>
public SqlGetRequest(Id id): base(r => r.Required("id", id))
{
}

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

// values part of the url path
[IgnoreDataMember]
Id ISqlGetRequest.Id => Self.RouteValues.Get<Id>("id");
// Request parameters
///<summary>Separator for CSV results</summary>
public string Delimiter
{
get => Q<string>("delimiter");
set => Q("delimiter", value);
}

///<summary>Short version of the Accept header, e.g. json, yaml</summary>
public string Format
{
get => Q<string>("format");
set => Q("format", value);
}

///<summary>Retention period for the search and its results</summary>
public Time KeepAlive
{
get => Q<Time>("keep_alive");
set => Q("keep_alive", value);
}

///<summary>Duration to wait for complete results</summary>
public Time WaitForCompletionTimeout
{
get => Q<Time>("wait_for_completion_timeout");
set => Q("wait_for_completion_timeout", value);
}
}

[InterfaceDataContract]
public partial interface ISqlSearchStatusRequest : IRequest<SqlSearchStatusRequestParameters>
{
Expand Down
19 changes: 19 additions & 0 deletions src/Nest/XPack/Sql/Get/SqlGetRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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>
/// Returns results for an async SQL search or a stored synchronous SQL search.
/// </summary>
[MapsApi("sql.get_async.json")]
[ReadAs(typeof(SqlGetRequest))]
public partial interface ISqlGetRequest { }

/// <inheritdoc cref="ISqlGetRequest"/>
public partial class SqlGetRequest { }

/// <inheritdoc cref="ISqlGetRequest"/>
public partial class SqlGetDescriptor { }
}
13 changes: 13 additions & 0 deletions src/Nest/XPack/Sql/Get/SqlGetResponse.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// A response to an SQL get async search request.
/// </summary>
public class SqlGetResponse : QuerySqlResponse
{
}
}
3 changes: 3 additions & 0 deletions src/Nest/XPack/Sql/Status/SqlSearchStatusRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Nest
{
/// <summary>
/// Returns the current status of an async SQL search or a stored synchronous SQL search.
/// </summary>
[MapsApi("sql.get_async_status")]
[ReadAs(typeof(EqlSearchStatusRequest))]
public partial interface ISqlSearchStatusRequest { }
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 @@ -300,6 +300,7 @@ internal static class ApiUrlsLookups
internal static ApiUrls SnapshotVerifyRepository = new ApiUrls(new[]{"_snapshot/{repository}/_verify"});
internal static ApiUrls SqlClearCursor = new ApiUrls(new[]{"_sql/close"});
internal static ApiUrls SqlDelete = new ApiUrls(new[]{"_sql/async/delete/{id}"});
internal static ApiUrls SqlGet = new ApiUrls(new[]{"_sql/async/{id}"});
internal static ApiUrls SqlSearchStatus = new ApiUrls(new[]{"_sql/async/status/{id}"});
internal static ApiUrls SqlQuery = new ApiUrls(new[]{"_sql"});
internal static ApiUrls SqlTranslate = new ApiUrls(new[]{"_sql/translate"});
Expand Down
21 changes: 21 additions & 0 deletions tests/Tests/XPack/Sql/Get/SqlGetUrlTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.XPack.Sql.Get
{
public class SqlGetUrlTests : UrlTestsBase
{
[U] public override async Task Urls() => await GET("/_sql/async/search_id")
.Fluent(c => c.Sql.Get("search_id", f => f))
.Request(c => c.Sql.Get(new SqlGetRequest("search_id")))
.FluentAsync(c => c.Sql.GetAsync("search_id", f => f))
.RequestAsync(c => c.Sql.GetAsync(new SqlGetRequest("search_id")));
}
}