Skip to content

Commit 11c24d1

Browse files
Add NEST support for EQL delete API (#5667) (#5668)
* Add request and response for delete EQL * Generate code * Add tests Co-authored-by: Steve Gordon <[email protected]>
1 parent e7c9d83 commit 11c24d1

File tree

10 files changed

+198
-4
lines changed

10 files changed

+198
-4
lines changed

src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.Eql.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
namespace Elasticsearch.Net.Specification.EqlApi
4444
{
4545
///<summary>Request options for Delete <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
46-
public class DeleteRequestParameters : RequestParameters<DeleteRequestParameters>
46+
public class EqlDeleteRequestParameters : RequestParameters<EqlDeleteRequestParameters>
4747
{
4848
public override HttpMethod DefaultHttpMethod => HttpMethod.DELETE;
4949
public override bool SupportsBody => false;

src/Elasticsearch.Net/ElasticLowLevelClient.Eql.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ internal LowLevelEqlNamespace(ElasticLowLevelClient client): base(client)
6464
///<summary>DELETE on /_eql/search/{id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
6565
///<param name = "id">The async search ID</param>
6666
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
67-
public TResponse Delete<TResponse>(string id, DeleteRequestParameters requestParameters = null)
67+
public TResponse Delete<TResponse>(string id, EqlDeleteRequestParameters requestParameters = null)
6868
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(DELETE, Url($"_eql/search/{id:id}"), null, RequestParams(requestParameters));
6969
///<summary>DELETE on /_eql/search/{id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
7070
///<param name = "id">The async search ID</param>
7171
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
7272
[MapsApi("eql.delete", "id")]
73-
public Task<TResponse> DeleteAsync<TResponse>(string id, DeleteRequestParameters requestParameters = null, CancellationToken ctx = default)
73+
public Task<TResponse> DeleteAsync<TResponse>(string id, EqlDeleteRequestParameters requestParameters = null, CancellationToken ctx = default)
7474
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(DELETE, Url($"_eql/search/{id:id}"), ctx, null, RequestParams(requestParameters));
7575
///<summary>GET on /_eql/search/{id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
7676
///<param name = "id">The async search ID</param>

src/Nest/Descriptors.Eql.cs

+21
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@
4848
// ReSharper disable RedundantNameQualifier
4949
namespace Nest
5050
{
51+
///<summary>Descriptor for Delete <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
52+
public partial class EqlDeleteDescriptor : RequestDescriptorBase<EqlDeleteDescriptor, EqlDeleteRequestParameters, IEqlDeleteRequest>, IEqlDeleteRequest
53+
{
54+
internal override ApiUrls ApiUrls => ApiUrlsLookups.EqlDelete;
55+
///<summary>/_eql/search/{id}</summary>
56+
///<param name = "id">this parameter is required</param>
57+
public EqlDeleteDescriptor(Id id): base(r => r.Required("id", id))
58+
{
59+
}
60+
61+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
62+
[SerializationConstructor]
63+
protected EqlDeleteDescriptor(): base()
64+
{
65+
}
66+
67+
// values part of the url path
68+
Id IEqlDeleteRequest.Id => Self.RouteValues.Get<Id>("id");
69+
// Request parameters
70+
}
71+
5172
///<summary>Descriptor for Get <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
5273
public partial class EqlGetDescriptor : RequestDescriptorBase<EqlGetDescriptor, EqlGetRequestParameters, IEqlGetRequest>, IEqlGetRequest
5374
{

src/Nest/ElasticClient.Eql.cs

+24
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,30 @@ internal EqlNamespace(ElasticClient client): base(client)
5454
{
5555
}
5656

57+
/// <summary>
58+
/// <c>DELETE</c> request to the <c>eql.delete</c> API, read more about this API online:
59+
/// <para></para>
60+
/// <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>
61+
/// </summary>
62+
public EqlDeleteResponse Delete(Id id, Func<EqlDeleteDescriptor, IEqlDeleteRequest> selector = null) => Delete(selector.InvokeOrDefault(new EqlDeleteDescriptor(id: id)));
63+
/// <summary>
64+
/// <c>DELETE</c> request to the <c>eql.delete</c> API, read more about this API online:
65+
/// <para></para>
66+
/// <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>
67+
/// </summary>
68+
public Task<EqlDeleteResponse> DeleteAsync(Id id, Func<EqlDeleteDescriptor, IEqlDeleteRequest> selector = null, CancellationToken ct = default) => DeleteAsync(selector.InvokeOrDefault(new EqlDeleteDescriptor(id: id)), ct);
69+
/// <summary>
70+
/// <c>DELETE</c> request to the <c>eql.delete</c> API, read more about this API online:
71+
/// <para></para>
72+
/// <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>
73+
/// </summary>
74+
public EqlDeleteResponse Delete(IEqlDeleteRequest request) => DoRequest<IEqlDeleteRequest, EqlDeleteResponse>(request, request.RequestParameters);
75+
/// <summary>
76+
/// <c>DELETE</c> request to the <c>eql.delete</c> API, read more about this API online:
77+
/// <para></para>
78+
/// <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>
79+
/// </summary>
80+
public Task<EqlDeleteResponse> DeleteAsync(IEqlDeleteRequest request, CancellationToken ct = default) => DoRequestAsync<IEqlDeleteRequest, EqlDeleteResponse>(request, request.RequestParameters, ct);
5781
/// <summary>
5882
/// <c>GET</c> request to the <c>eql.get</c> API, read more about this API online:
5983
/// <para></para>

src/Nest/Requests.Eql.cs

+33
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,39 @@
4949
// ReSharper disable RedundantNameQualifier
5050
namespace Nest
5151
{
52+
[InterfaceDataContract]
53+
public partial interface IEqlDeleteRequest : IRequest<EqlDeleteRequestParameters>
54+
{
55+
[IgnoreDataMember]
56+
Id Id
57+
{
58+
get;
59+
}
60+
}
61+
62+
///<summary>Request for Delete <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
63+
public partial class EqlDeleteRequest : PlainRequestBase<EqlDeleteRequestParameters>, IEqlDeleteRequest
64+
{
65+
protected IEqlDeleteRequest Self => this;
66+
internal override ApiUrls ApiUrls => ApiUrlsLookups.EqlDelete;
67+
///<summary>/_eql/search/{id}</summary>
68+
///<param name = "id">this parameter is required</param>
69+
public EqlDeleteRequest(Id id): base(r => r.Required("id", id))
70+
{
71+
}
72+
73+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
74+
[SerializationConstructor]
75+
protected EqlDeleteRequest(): base()
76+
{
77+
}
78+
79+
// values part of the url path
80+
[IgnoreDataMember]
81+
Id IEqlDeleteRequest.Id => Self.RouteValues.Get<Id>("id");
82+
// Request parameters
83+
}
84+
5285
[InterfaceDataContract]
5386
public partial interface IEqlGetRequest : IRequest<EqlGetRequestParameters>
5487
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
namespace Nest
21+
{
22+
/// <summary>
23+
/// Request to deletes an async EQL search or a stored synchronous EQL search.
24+
/// The delete API also deletes results for the search.
25+
/// </summary>
26+
[MapsApi("eql.delete.json")]
27+
[ReadAs(typeof(EqlDeleteRequest))]
28+
public partial interface IEqlDeleteRequest { }
29+
30+
/// <inheritdoc cref="IEqlDeleteRequest"/>
31+
public partial class EqlDeleteRequest
32+
{
33+
}
34+
35+
/// <inheritdoc cref="IEqlDeleteRequest"/>
36+
public partial class EqlDeleteDescriptor
37+
{
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
namespace Nest
21+
{
22+
public class EqlDeleteResponse : AcknowledgedResponseBase { }
23+
}

src/Nest/_Generated/ApiUrlsLookup.generated.cs

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ internal static class ApiUrlsLookups
106106
internal static ApiUrls EnrichGetPolicy = new ApiUrls(new[]{"_enrich/policy/{name}", "_enrich/policy/"});
107107
internal static ApiUrls EnrichPutPolicy = new ApiUrls(new[]{"_enrich/policy/{name}"});
108108
internal static ApiUrls EnrichStats = new ApiUrls(new[]{"_enrich/_stats"});
109+
internal static ApiUrls EqlDelete = new ApiUrls(new[]{"_eql/search/{id}"});
109110
internal static ApiUrls EqlGet = new ApiUrls(new[]{"_eql/search/{id}"});
110111
internal static ApiUrls EqlSearchStatus = new ApiUrls(new[]{"_eql/search/status/{id}"});
111112
internal static ApiUrls EqlSearch = new ApiUrls(new[]{"{index}/_eql/search"});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
using System.Threading.Tasks;
21+
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
22+
using Nest;
23+
using Tests.Framework.EndpointTests;
24+
using static Tests.Framework.EndpointTests.UrlTester;
25+
26+
namespace Tests.XPack.Eql.Delete
27+
{
28+
public class EqlDeleteUrlTests : UrlTestsBase
29+
{
30+
[U] public override async Task Urls() => await DELETE("/_eql/search/search_id")
31+
.Fluent(c => c.Eql.Delete("search_id", f => f))
32+
.Request(c => c.Eql.Delete(new EqlDeleteRequest("search_id")))
33+
.FluentAsync(c => c.Eql.DeleteAsync("search_id", f => f))
34+
.RequestAsync(c => c.Eql.DeleteAsync(new EqlDeleteRequest("search_id")));
35+
}
36+
}

tests/Tests/XPack/Eql/EqlSearchApiCoordinatedTests.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
using System;
2120
using System.Linq;
2221
using System.Threading.Tasks;
2322
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
@@ -38,6 +37,7 @@ public class EqlSearchApiCoordinatedTests : CoordinatedIntegrationTestBase<TimeS
3837
private const string StatusStep = nameof(StatusStep);
3938
private const string GetStep = nameof(GetStep);
4039
private const string WaitStep = nameof(WaitStep);
40+
private const string DeleteStep = nameof(DeleteStep);
4141

4242
public EqlSearchApiCoordinatedTests(TimeSeriesCluster cluster, EndpointUsage usage) : base(new CoordinatedUsage(cluster, usage, testOnlyOne: true)
4343
{
@@ -96,6 +96,17 @@ public EqlSearchApiCoordinatedTests(TimeSeriesCluster cluster, EndpointUsage usa
9696
(v, c, r) => c.Eql.GetAsync<Log>(r),
9797
uniqueValueSelector: values => values.ExtendedValue<string>("id")
9898
)
99+
},
100+
{DeleteStep, u =>
101+
u.Calls<EqlDeleteDescriptor, EqlDeleteRequest, IEqlDeleteRequest, EqlDeleteResponse>(
102+
v => new EqlDeleteRequest(v),
103+
(v, d) => d,
104+
(v, c, f) => c.Eql.Delete(v, f),
105+
(v, c, f) => c.Eql.DeleteAsync(v, f),
106+
(v, c, r) => c.Eql.Delete(r),
107+
(v, c, r) => c.Eql.DeleteAsync(r),
108+
uniqueValueSelector: values => values.ExtendedValue<string>("id")
109+
)
99110
}
100111
}) { }
101112

@@ -134,5 +145,11 @@ [I] public async Task EqlGetResponse() => await Assert<EqlGetResponse<Log>>(GetS
134145
firstEvent.Id.Should().NotBeNullOrEmpty();
135146
firstEvent.Source.Event.Category.Should().BeOneOf(Log.EventCategories);
136147
});
148+
149+
[I] public async Task EqlDeleteResponse() => await Assert<EqlDeleteResponse>(DeleteStep, r =>
150+
{
151+
r.ShouldBeValid();
152+
r.Acknowledged.Should().BeTrue();
153+
});
137154
}
138155
}

0 commit comments

Comments
 (0)