Skip to content
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

Add NEST support for EQL Search API #5658

Merged
merged 21 commits 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
2 changes: 1 addition & 1 deletion .github/check-license-headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ NLINES=$(wc -l .github/license-header.txt | awk '{print $1}')
function check_license_header {
local f
f=$1
if ! diff .github/license-header.txt <(head -$NLINES "$f") >/dev/null; then
if ! diff -a --strip-trailing-cr .github/license-header.txt <(head -$NLINES "$f") >/dev/null; then
echo "check-license-headers: error: '$f' does not have required license header, see 'diff -u .github/license-header.txt <(head -$NLINES $f)'"
return 1
else
Expand Down
4 changes: 0 additions & 4 deletions src/ApiGenerator/Configuration/CodeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ public static class CodeConfiguration
"cluster.get_component_template.json", // 7.8 experimental
"cluster.put_component_template.json", // 7.8 experimental
"cluster.exists_component_template.json", // 7.8 experimental

"eql.search.json", // 7.9 beta
"eql.get.json", // 7.9 beta
"eql.delete.json", // 7.9 beta
};

/// <summary>
Expand Down
12 changes: 12 additions & 0 deletions src/ApiGenerator/RestSpecification/_Patches/eql.search.patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"eql.search": {
"url": {
"parts": {
"index": {
"type" : "list",
"description" : "A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices"
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class GetStatusRequestParameters : RequestParameters<GetStatusRequestPara
}

///<summary>Request options for Search <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
public class SearchRequestParameters : RequestParameters<SearchRequestParameters>
public class EqlSearchRequestParameters : RequestParameters<EqlSearchRequestParameters>
{
public override HttpMethod DefaultHttpMethod => HttpMethod.POST;
public override bool SupportsBody => true;
Expand Down
8 changes: 4 additions & 4 deletions src/Elasticsearch.Net/ElasticLowLevelClient.Eql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ public TResponse GetStatus<TResponse>(string id, GetStatusRequestParameters requ
public Task<TResponse> GetStatusAsync<TResponse>(string id, GetStatusRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(GET, Url($"_eql/search/status/{id:id}"), ctx, null, RequestParams(requestParameters));
///<summary>POST on /{index}/_eql/search <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
///<param name = "index">The name of the index to scope the operation</param>
///<param name = "index">A comma-separated list of index names to search; use the special string `_all` or Indices.All to perform the operation on all indices</param>
///<param name = "body">Eql request body. Use the `query` to limit the query scope.</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public TResponse Search<TResponse>(string index, PostData body, SearchRequestParameters requestParameters = null)
public TResponse Search<TResponse>(string index, PostData body, EqlSearchRequestParameters requestParameters = null)
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(POST, Url($"{index:index}/_eql/search"), body, RequestParams(requestParameters));
///<summary>POST on /{index}/_eql/search <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
///<param name = "index">The name of the index to scope the operation</param>
///<param name = "index">A comma-separated list of index names to search; use the special string `_all` or Indices.All to perform the operation on all indices</param>
///<param name = "body">Eql request body. Use the `query` to limit the query scope.</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
[MapsApi("eql.search", "index, body")]
public Task<TResponse> SearchAsync<TResponse>(string index, PostData body, SearchRequestParameters requestParameters = null, CancellationToken ctx = default)
public Task<TResponse> SearchAsync<TResponse>(string index, PostData body, EqlSearchRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(POST, Url($"{index:index}/_eql/search"), ctx, body, RequestParams(requestParameters));
}
}
83 changes: 83 additions & 0 deletions src/Nest/Descriptors.Eql.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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.
*/
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
// -----------------------------------------------
//
// This file is automatically generated
// Please do not edit these files manually
// Run the following in the root of the repos:
//
// *NIX : ./build.sh codegen
// Windows : build.bat codegen
//
// -----------------------------------------------
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using Elasticsearch.Net;
using Elasticsearch.Net.Utf8Json;
using Elasticsearch.Net.Specification.EqlApi;

// ReSharper disable RedundantBaseConstructorCall
// ReSharper disable UnusedTypeParameter
// ReSharper disable PartialMethodWithSinglePart
// ReSharper disable RedundantNameQualifier
namespace Nest
{
///<summary>Descriptor for Search <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html</para></summary>
public partial class EqlSearchDescriptor<TInferDocument> : RequestDescriptorBase<EqlSearchDescriptor<TInferDocument>, EqlSearchRequestParameters, IEqlSearchRequest<TInferDocument>>, IEqlSearchRequest<TInferDocument>
{
internal override ApiUrls ApiUrls => ApiUrlsLookups.EqlSearch;
///<summary>/{index}/_eql/search</summary>
///<param name = "index">this parameter is required</param>
public EqlSearchDescriptor(Indices index): base(r => r.Required("index", index))
{
}

///<summary>/{index}/_eql/search</summary>
public EqlSearchDescriptor(): this(typeof(TInferDocument))
{
}

// values part of the url path
Indices IEqlSearchRequest.Index => Self.RouteValues.Get<Indices>("index");
///<summary>A comma-separated list of index names to search; use the special string `_all` or Indices.All to perform the operation on all indices</summary>
public EqlSearchDescriptor<TInferDocument> Index(Indices index) => Assign(index, (a, v) => a.RouteValues.Required("index", v));
///<summary>a shortcut into calling Index(typeof(TOther))</summary>
public EqlSearchDescriptor<TInferDocument> Index<TOther>()
where TOther : class => Assign(typeof(TOther), (a, v) => a.RouteValues.Required("index", (Indices)v));
///<summary>A shortcut into calling Index(Indices.All)</summary>
public EqlSearchDescriptor<TInferDocument> AllIndices() => Index(Indices.All);
// Request parameters
///<summary>Update the time interval in which the results (partial or final) for this search will be available</summary>
public EqlSearchDescriptor<TInferDocument> KeepAlive(Time keepalive) => Qs("keep_alive", keepalive);
///<summary>Control whether the response should be stored in the cluster if it completed within the provided [wait_for_completion] time (default: false)</summary>
public EqlSearchDescriptor<TInferDocument> KeepOnCompletion(bool? keeponcompletion = true) => Qs("keep_on_completion", keeponcompletion);
///<summary>Specify the time that the request should block waiting for the final response</summary>
public EqlSearchDescriptor<TInferDocument> WaitForCompletionTimeout(Time waitforcompletiontimeout) => Qs("wait_for_completion_timeout", waitforcompletiontimeout);
}
}
100 changes: 100 additions & 0 deletions src/Nest/ElasticClient.Eql.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.
*/
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
// -----------------------------------------------
//
// This file is automatically generated
// Please do not edit these files manually
// Run the following in the root of the repos:
//
// *NIX : ./build.sh codegen
// Windows : build.bat codegen
//
// -----------------------------------------------
// ReSharper disable RedundantUsingDirective
using System;
using System.Threading;
using System.Threading.Tasks;
using Elasticsearch.Net.Specification.EqlApi;

// ReSharper disable once CheckNamespace
// ReSharper disable RedundantTypeArgumentsOfMethod
namespace Nest.Specification.EqlApi
{
///<summary>
/// Eql APIs.
/// <para>Not intended to be instantiated directly. Use the <see cref = "IElasticClient.Eql"/> property
/// on <see cref = "IElasticClient"/>.
///</para>
///</summary>
public class EqlNamespace : NamespacedClientProxy
{
internal EqlNamespace(ElasticClient client): base(client)
{
}

/// <summary>
/// <c>POST</c> request to the <c>eql.search</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 EqlSearchResponse<TDocument> Search<TInferDocument, TDocument>(Func<EqlSearchDescriptor<TInferDocument>, IEqlSearchRequest> selector = null)
where TInferDocument : class where TDocument : class => Search<TDocument>(selector.InvokeOrDefault(new EqlSearchDescriptor<TInferDocument>()));
/// <summary>
/// <c>POST</c> request to the <c>eql.search</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<EqlSearchResponse<TDocument>> SearchAsync<TInferDocument, TDocument>(Func<EqlSearchDescriptor<TInferDocument>, IEqlSearchRequest> selector = null, CancellationToken ct = default)
where TInferDocument : class where TDocument : class => SearchAsync<TDocument>(selector.InvokeOrDefault(new EqlSearchDescriptor<TInferDocument>()), ct);
/// <summary>
/// <c>POST</c> request to the <c>eql.search</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 EqlSearchResponse<TDocument> Search<TDocument>(Func<EqlSearchDescriptor<TDocument>, IEqlSearchRequest> selector = null)
where TDocument : class => Search<TDocument>(selector.InvokeOrDefault(new EqlSearchDescriptor<TDocument>()));
/// <summary>
/// <c>POST</c> request to the <c>eql.search</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<EqlSearchResponse<TDocument>> SearchAsync<TDocument>(Func<EqlSearchDescriptor<TDocument>, IEqlSearchRequest> selector = null, CancellationToken ct = default)
where TDocument : class => SearchAsync<TDocument>(selector.InvokeOrDefault(new EqlSearchDescriptor<TDocument>()), ct);
/// <summary>
/// <c>POST</c> request to the <c>eql.search</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 EqlSearchResponse<TDocument> Search<TDocument>(IEqlSearchRequest request)
where TDocument : class => DoRequest<IEqlSearchRequest, EqlSearchResponse<TDocument>>(request, request.RequestParameters);
/// <summary>
/// <c>POST</c> request to the <c>eql.search</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<EqlSearchResponse<TDocument>> SearchAsync<TDocument>(IEqlSearchRequest request, CancellationToken ct = default)
where TDocument : class => DoRequestAsync<IEqlSearchRequest, EqlSearchResponse<TDocument>>(request, request.RequestParameters, ct);
}
}
9 changes: 9 additions & 0 deletions src/Nest/ElasticClient.NoNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
using Nest.Specification.CrossClusterReplicationApi;
using Nest.Specification.DanglingIndicesApi;
using Nest.Specification.EnrichApi;
using Nest.Specification.EqlApi;
using Nest.Specification.GraphApi;
using Nest.Specification.IndexLifecycleManagementApi;
using Nest.Specification.IndicesApi;
Expand Down Expand Up @@ -111,6 +112,13 @@ public EnrichNamespace Enrich
private set;
}

///<summary>Eql APIs</summary>
public EqlNamespace Eql
{
get;
private set;
}

///<summary>Graph APIs</summary>
public GraphNamespace Graph
{
Expand Down Expand Up @@ -238,6 +246,7 @@ partial void SetupNamespaces()
CrossClusterReplication = new CrossClusterReplicationNamespace(this);
DanglingIndices = new DanglingIndicesNamespace(this);
Enrich = new EnrichNamespace(this);
Eql = new EqlNamespace(this);
Graph = new GraphNamespace(this);
IndexLifecycleManagement = new IndexLifecycleManagementNamespace(this);
Indices = new IndicesNamespace(this);
Expand Down
7 changes: 7 additions & 0 deletions src/Nest/IElasticClient.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
using Nest.Specification.CrossClusterReplicationApi;
using Nest.Specification.DanglingIndicesApi;
using Nest.Specification.EnrichApi;
using Nest.Specification.EqlApi;
using Nest.Specification.GraphApi;
using Nest.Specification.IndexLifecycleManagementApi;
using Nest.Specification.IndicesApi;
Expand Down Expand Up @@ -106,6 +107,12 @@ EnrichNamespace Enrich
get;
}

///<summary>Eql APIs</summary>
EqlNamespace Eql
{
get;
}

///<summary>Graph APIs</summary>
GraphNamespace Graph
{
Expand Down
Loading