Skip to content

[Backport 7.x] Add NEST support for EQL delete API #5668

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
May 4, 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 @@ -43,7 +43,7 @@
namespace Elasticsearch.Net.Specification.EqlApi
{
///<summary>Request options for Delete <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
public class DeleteRequestParameters : RequestParameters<DeleteRequestParameters>
public class EqlDeleteRequestParameters : RequestParameters<EqlDeleteRequestParameters>
{
public override HttpMethod DefaultHttpMethod => HttpMethod.DELETE;
public override bool SupportsBody => false;
Expand Down
4 changes: 2 additions & 2 deletions src/Elasticsearch.Net/ElasticLowLevelClient.Eql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ internal LowLevelEqlNamespace(ElasticLowLevelClient client): base(client)
///<summary>DELETE on /_eql/search/{id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-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 Delete<TResponse>(string id, DeleteRequestParameters requestParameters = null)
public TResponse Delete<TResponse>(string id, EqlDeleteRequestParameters requestParameters = null)
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(DELETE, Url($"_eql/search/{id:id}"), null, RequestParams(requestParameters));
///<summary>DELETE on /_eql/search/{id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-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("eql.delete", "id")]
public Task<TResponse> DeleteAsync<TResponse>(string id, DeleteRequestParameters requestParameters = null, CancellationToken ctx = default)
public Task<TResponse> DeleteAsync<TResponse>(string id, EqlDeleteRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(DELETE, Url($"_eql/search/{id:id}"), ctx, null, RequestParams(requestParameters));
///<summary>GET on /_eql/search/{id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
///<param name = "id">The async search ID</param>
Expand Down
21 changes: 21 additions & 0 deletions src/Nest/Descriptors.Eql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@
// ReSharper disable RedundantNameQualifier
namespace Nest
{
///<summary>Descriptor for Delete <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
public partial class EqlDeleteDescriptor : RequestDescriptorBase<EqlDeleteDescriptor, EqlDeleteRequestParameters, IEqlDeleteRequest>, IEqlDeleteRequest
{
internal override ApiUrls ApiUrls => ApiUrlsLookups.EqlDelete;
///<summary>/_eql/search/{id}</summary>
///<param name = "id">this parameter is required</param>
public EqlDeleteDescriptor(Id id): base(r => r.Required("id", id))
{
}

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

// values part of the url path
Id IEqlDeleteRequest.Id => Self.RouteValues.Get<Id>("id");
// Request parameters
}

///<summary>Descriptor for Get <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
public partial class EqlGetDescriptor : RequestDescriptorBase<EqlGetDescriptor, EqlGetRequestParameters, IEqlGetRequest>, IEqlGetRequest
{
Expand Down
24 changes: 24 additions & 0 deletions src/Nest/ElasticClient.Eql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ internal EqlNamespace(ElasticClient client): base(client)
{
}

/// <summary>
/// <c>DELETE</c> request to the <c>eql.delete</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</a>
/// </summary>
public EqlDeleteResponse Delete(Id id, Func<EqlDeleteDescriptor, IEqlDeleteRequest> selector = null) => Delete(selector.InvokeOrDefault(new EqlDeleteDescriptor(id: id)));
/// <summary>
/// <c>DELETE</c> request to the <c>eql.delete</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</a>
/// </summary>
public Task<EqlDeleteResponse> DeleteAsync(Id id, Func<EqlDeleteDescriptor, IEqlDeleteRequest> selector = null, CancellationToken ct = default) => DeleteAsync(selector.InvokeOrDefault(new EqlDeleteDescriptor(id: id)), ct);
/// <summary>
/// <c>DELETE</c> request to the <c>eql.delete</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</a>
/// </summary>
public EqlDeleteResponse Delete(IEqlDeleteRequest request) => DoRequest<IEqlDeleteRequest, EqlDeleteResponse>(request, request.RequestParameters);
/// <summary>
/// <c>DELETE</c> request to the <c>eql.delete</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</a>
/// </summary>
public Task<EqlDeleteResponse> DeleteAsync(IEqlDeleteRequest request, CancellationToken ct = default) => DoRequestAsync<IEqlDeleteRequest, EqlDeleteResponse>(request, request.RequestParameters, ct);
/// <summary>
/// <c>GET</c> request to the <c>eql.get</c> API, read more about this API online:
/// <para></para>
Expand Down
33 changes: 33 additions & 0 deletions src/Nest/Requests.Eql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,39 @@
// ReSharper disable RedundantNameQualifier
namespace Nest
{
[InterfaceDataContract]
public partial interface IEqlDeleteRequest : IRequest<EqlDeleteRequestParameters>
{
[IgnoreDataMember]
Id Id
{
get;
}
}

///<summary>Request for Delete <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
public partial class EqlDeleteRequest : PlainRequestBase<EqlDeleteRequestParameters>, IEqlDeleteRequest
{
protected IEqlDeleteRequest Self => this;
internal override ApiUrls ApiUrls => ApiUrlsLookups.EqlDelete;
///<summary>/_eql/search/{id}</summary>
///<param name = "id">this parameter is required</param>
public EqlDeleteRequest(Id id): base(r => r.Required("id", id))
{
}

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

// values part of the url path
[IgnoreDataMember]
Id IEqlDeleteRequest.Id => Self.RouteValues.Get<Id>("id");
// Request parameters
}

[InterfaceDataContract]
public partial interface IEqlGetRequest : IRequest<EqlGetRequestParameters>
{
Expand Down
39 changes: 39 additions & 0 deletions src/Nest/XPack/Eql/Delete/EqlDeleteRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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
{
/// <summary>
/// Request to deletes an async EQL search or a stored synchronous EQL search.
/// The delete API also deletes results for the search.
/// </summary>
[MapsApi("eql.delete.json")]
[ReadAs(typeof(EqlDeleteRequest))]
public partial interface IEqlDeleteRequest { }

/// <inheritdoc cref="IEqlDeleteRequest"/>
public partial class EqlDeleteRequest
{
}

/// <inheritdoc cref="IEqlDeleteRequest"/>
public partial class EqlDeleteDescriptor
{
}
}
23 changes: 23 additions & 0 deletions src/Nest/XPack/Eql/Delete/EqlDeleteResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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
{
public class EqlDeleteResponse : AcknowledgedResponseBase { }
}
1 change: 1 addition & 0 deletions src/Nest/_Generated/ApiUrlsLookup.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 EqlDelete = new ApiUrls(new[]{"_eql/search/{id}"});
internal static ApiUrls EqlGet = new ApiUrls(new[]{"_eql/search/{id}"});
internal static ApiUrls EqlSearchStatus = new ApiUrls(new[]{"_eql/search/status/{id}"});
internal static ApiUrls EqlSearch = new ApiUrls(new[]{"{index}/_eql/search"});
Expand Down
36 changes: 36 additions & 0 deletions tests/Tests/XPack/Eql/Delete/EqlDeleteUrlTests.cs
Original file line number Diff line number Diff line change
@@ -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.Delete
{
public class EqlDeleteUrlTests : UrlTestsBase
{
[U] public override async Task Urls() => await DELETE("/_eql/search/search_id")
.Fluent(c => c.Eql.Delete("search_id", f => f))
.Request(c => c.Eql.Delete(new EqlDeleteRequest("search_id")))
.FluentAsync(c => c.Eql.DeleteAsync("search_id", f => f))
.RequestAsync(c => c.Eql.DeleteAsync(new EqlDeleteRequest("search_id")));
}
}
19 changes: 18 additions & 1 deletion tests/Tests/XPack/Eql/EqlSearchApiCoordinatedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/

using System;
using System.Linq;
using System.Threading.Tasks;
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
Expand All @@ -38,6 +37,7 @@ public class EqlSearchApiCoordinatedTests : CoordinatedIntegrationTestBase<TimeS
private const string StatusStep = nameof(StatusStep);
private const string GetStep = nameof(GetStep);
private const string WaitStep = nameof(WaitStep);
private const string DeleteStep = nameof(DeleteStep);

public EqlSearchApiCoordinatedTests(TimeSeriesCluster cluster, EndpointUsage usage) : base(new CoordinatedUsage(cluster, usage, testOnlyOne: true)
{
Expand Down Expand Up @@ -96,6 +96,17 @@ public EqlSearchApiCoordinatedTests(TimeSeriesCluster cluster, EndpointUsage usa
(v, c, r) => c.Eql.GetAsync<Log>(r),
uniqueValueSelector: values => values.ExtendedValue<string>("id")
)
},
{DeleteStep, u =>
u.Calls<EqlDeleteDescriptor, EqlDeleteRequest, IEqlDeleteRequest, EqlDeleteResponse>(
v => new EqlDeleteRequest(v),
(v, d) => d,
(v, c, f) => c.Eql.Delete(v, f),
(v, c, f) => c.Eql.DeleteAsync(v, f),
(v, c, r) => c.Eql.Delete(r),
(v, c, r) => c.Eql.DeleteAsync(r),
uniqueValueSelector: values => values.ExtendedValue<string>("id")
)
}
}) { }

Expand Down Expand Up @@ -134,5 +145,11 @@ [I] public async Task EqlGetResponse() => await Assert<EqlGetResponse<Log>>(GetS
firstEvent.Id.Should().NotBeNullOrEmpty();
firstEvent.Source.Event.Category.Should().BeOneOf(Log.EventCategories);
});

[I] public async Task EqlDeleteResponse() => await Assert<EqlDeleteResponse>(DeleteStep, r =>
{
r.ShouldBeValid();
r.Acknowledged.Should().BeTrue();
});
}
}