Skip to content

Implement cat.ml_datafeeds #4564

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 4 commits into from
Apr 17, 2020
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
1 change: 0 additions & 1 deletion src/ApiGenerator/Configuration/CodeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public static class CodeConfiguration
"async_search.get.json",
"async_search.submit.json",
"cat.ml_data_frame_analytics.json",
"cat.ml_datafeeds.json",
"cluster.delete_component_template.json",
"cluster.get_component_template.json",
"cluster.put_component_template.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ public bool? Verbose
}
}

///<summary>Request options for MlDatafeeds <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html</para></summary>
public class MlDatafeedsRequestParameters : RequestParameters<MlDatafeedsRequestParameters>
///<summary>Request options for Datafeeds <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html</para></summary>
public class CatDatafeedsRequestParameters : RequestParameters<CatDatafeedsRequestParameters>
{
public override HttpMethod DefaultHttpMethod => HttpMethod.GET;
///<summary>Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)</summary>
Expand Down
8 changes: 4 additions & 4 deletions src/Elasticsearch.Net/ElasticLowLevelClient.Cat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,23 @@ public Task<TResponse> MlDataFrameAnalyticsAsync<TResponse>(string id, MlDataFra
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(GET, Url($"_cat/ml/data_frame/analytics/{id:id}"), ctx, null, RequestParams(requestParameters));
///<summary>GET on /_cat/ml/datafeeds <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html</para></summary>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public TResponse MlDatafeeds<TResponse>(MlDatafeedsRequestParameters requestParameters = null)
public TResponse Datafeeds<TResponse>(CatDatafeedsRequestParameters requestParameters = null)
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(GET, "_cat/ml/datafeeds", null, RequestParams(requestParameters));
///<summary>GET on /_cat/ml/datafeeds <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html</para></summary>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
[MapsApi("cat.ml_datafeeds", "")]
public Task<TResponse> MlDatafeedsAsync<TResponse>(MlDatafeedsRequestParameters requestParameters = null, CancellationToken ctx = default)
public Task<TResponse> DatafeedsAsync<TResponse>(CatDatafeedsRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(GET, "_cat/ml/datafeeds", ctx, null, RequestParams(requestParameters));
///<summary>GET on /_cat/ml/datafeeds/{datafeed_id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html</para></summary>
///<param name = "datafeedId">The ID of the datafeeds stats to fetch</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public TResponse MlDatafeeds<TResponse>(string datafeedId, MlDatafeedsRequestParameters requestParameters = null)
public TResponse Datafeeds<TResponse>(string datafeedId, CatDatafeedsRequestParameters requestParameters = null)
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(GET, Url($"_cat/ml/datafeeds/{datafeedId:datafeedId}"), null, RequestParams(requestParameters));
///<summary>GET on /_cat/ml/datafeeds/{datafeed_id} <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html</para></summary>
///<param name = "datafeedId">The ID of the datafeeds stats to fetch</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
[MapsApi("cat.ml_datafeeds", "datafeed_id")]
public Task<TResponse> MlDatafeedsAsync<TResponse>(string datafeedId, MlDatafeedsRequestParameters requestParameters = null, CancellationToken ctx = default)
public Task<TResponse> DatafeedsAsync<TResponse>(string datafeedId, CatDatafeedsRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(GET, Url($"_cat/ml/datafeeds/{datafeedId:datafeedId}"), ctx, null, RequestParams(requestParameters));
///<summary>GET on /_cat/ml/anomaly_detectors <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-anomaly-detectors.html</para></summary>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
Expand Down
82 changes: 82 additions & 0 deletions src/Nest/Cat/CatDatafeeds/CatDatafeedsRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System.Runtime.Serialization;
using Elasticsearch.Net.Utf8Json;

namespace Nest
{
[DataContract]
public class CatDatafeedsRecord : ICatRecord
{
/// <summary>
/// For started datafeeds only, contains messages relating to the selection of a node.
/// </summary>
[DataMember(Name="assignment_explanation")]
public string AssignmentExplanation { get; internal set; }

/// <summary>
/// (Default) The number of buckets processed.
/// </summary>
[DataMember(Name="buckets.count")]
public string BucketsCount { get; internal set; }

/// <summary>
/// (Default) A numerical character string that uniquely identifies the datafeed. This identifier can contain lowercase alphanumeric
/// characters (a-z and 0-9), hyphens, and underscores. It must start and end with alphanumeric characters.
/// </summary>
[DataMember(Name="id")]
public string Id { get; internal set; }

/// <summary>
/// The network address of the node. For started datafeeds only, this information pertains to the node upon which the datafeed is started.
/// </summary>
[DataMember(Name="node.address")]
public string NodeAddress { get; internal set; }

/// <summary>
/// The ephemeral ID of the node. For started datafeeds only, this information pertains to the node upon which the datafeed is started.
/// </summary>
[DataMember(Name="node.ephemeral_id")]
public string NodeEphemeralId { get; internal set; }

/// <summary>
/// The unique identifier of the node. For started datafeeds only, this information pertains to the node upon which the datafeed is started.
/// </summary>
[DataMember(Name="node.id")]
public string NodeId { get; internal set; }

/// <summary>
/// The node name. For started datafeeds only, this information pertains to the node upon which the datafeed is started.
/// </summary>
[DataMember(Name="node.name")]
public string NodeName { get; internal set; }

/// <summary>
/// The average search time per bucket, in milliseconds.
/// </summary>
[DataMember(Name="search.bucket_avg")]
public string SearchBucketAvg { get; internal set; }

/// <summary>
/// (Default) The number of searches run by the datafeed.
/// </summary>
[DataMember(Name="search.count")]
public string SearchCount { get; internal set; }

/// <summary>
/// The exponential average search time per hour, in milliseconds.
/// </summary>
[DataMember(Name="search.exp_avg_hour")]
public string SearchExpAvgHour { get; internal set; }

/// <summary>
/// The total time the datafeed spent searching, in milliseconds.
/// </summary>
[DataMember(Name="search.time")]
public string SearchTime { get; internal set; }

/// <summary>
/// The status of the datafeed.
/// </summary>
[DataMember(Name="state")]
public DatafeedState State { get; internal set; }
}
}
9 changes: 9 additions & 0 deletions src/Nest/Cat/CatDatafeeds/CatDatafeedsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Nest
{
[MapsApi("cat.ml_datafeeds.json")]
public partial interface ICatDatafeedsRequest { }

public partial class CatDatafeedsRequest { }

public partial class CatDatafeedsDescriptor { }
}
34 changes: 34 additions & 0 deletions src/Nest/Descriptors.Cat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,40 @@ public partial class CatMasterDescriptor : RequestDescriptorBase<CatMasterDescri
public CatMasterDescriptor Verbose(bool? verbose = true) => Qs("v", verbose);
}

///<summary>Descriptor for Datafeeds <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html</para></summary>
public partial class CatDatafeedsDescriptor : RequestDescriptorBase<CatDatafeedsDescriptor, CatDatafeedsRequestParameters, ICatDatafeedsRequest>, ICatDatafeedsRequest
{
internal override ApiUrls ApiUrls => ApiUrlsLookups.CatDatafeeds;
///<summary>/_cat/ml/datafeeds</summary>
public CatDatafeedsDescriptor(): base()
{
}

///<summary>/_cat/ml/datafeeds/{datafeed_id}</summary>
///<param name = "datafeedId">Optional, accepts null</param>
public CatDatafeedsDescriptor(Id datafeedId): base(r => r.Optional("datafeed_id", datafeedId))
{
}

// values part of the url path
Id ICatDatafeedsRequest.DatafeedId => Self.RouteValues.Get<Id>("datafeed_id");
///<summary>The ID of the datafeeds stats to fetch</summary>
public CatDatafeedsDescriptor DatafeedId(Id datafeedId) => Assign(datafeedId, (a, v) => a.RouteValues.Optional("datafeed_id", v));
// Request parameters
///<summary>Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)</summary>
public CatDatafeedsDescriptor AllowNoDatafeeds(bool? allownodatafeeds = true) => Qs("allow_no_datafeeds", allownodatafeeds);
///<summary>a short version of the Accept header, e.g. json, yaml</summary>
public CatDatafeedsDescriptor Format(string format) => Qs("format", format);
///<summary>Comma-separated list of column names to display</summary>
public CatDatafeedsDescriptor Headers(params string[] headers) => Qs("h", headers);
///<summary>Return help information</summary>
public CatDatafeedsDescriptor Help(bool? help = true) => Qs("help", help);
///<summary>Comma-separated list of column names or column aliases to sort by</summary>
public CatDatafeedsDescriptor SortByColumns(params string[] sortbycolumns) => Qs("s", sortbycolumns);
///<summary>Verbose mode. Display column headers</summary>
public CatDatafeedsDescriptor Verbose(bool? verbose = true) => Qs("v", verbose);
}

///<summary>Descriptor for Jobs <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-anomaly-detectors.html</para></summary>
public partial class CatJobsDescriptor : RequestDescriptorBase<CatJobsDescriptor, CatJobsRequestParameters, ICatJobsRequest>, ICatJobsRequest
{
Expand Down
24 changes: 24 additions & 0 deletions src/Nest/ElasticClient.Cat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,30 @@ internal CatNamespace(ElasticClient client): base(client)
/// </summary>
public Task<CatResponse<CatMasterRecord>> MasterAsync(ICatMasterRequest request, CancellationToken ct = default) => DoCatAsync<ICatMasterRequest, CatMasterRequestParameters, CatMasterRecord>(request, ct);
/// <summary>
/// <c>GET</c> request to the <c>cat.ml_datafeeds</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html</a>
/// </summary>
public CatResponse<CatDatafeedsRecord> Datafeeds(Func<CatDatafeedsDescriptor, ICatDatafeedsRequest> selector = null) => Datafeeds(selector.InvokeOrDefault(new CatDatafeedsDescriptor()));
/// <summary>
/// <c>GET</c> request to the <c>cat.ml_datafeeds</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html</a>
/// </summary>
public Task<CatResponse<CatDatafeedsRecord>> DatafeedsAsync(Func<CatDatafeedsDescriptor, ICatDatafeedsRequest> selector = null, CancellationToken ct = default) => DatafeedsAsync(selector.InvokeOrDefault(new CatDatafeedsDescriptor()), ct);
/// <summary>
/// <c>GET</c> request to the <c>cat.ml_datafeeds</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html</a>
/// </summary>
public CatResponse<CatDatafeedsRecord> Datafeeds(ICatDatafeedsRequest request) => DoCat<ICatDatafeedsRequest, CatDatafeedsRequestParameters, CatDatafeedsRecord>(request);
/// <summary>
/// <c>GET</c> request to the <c>cat.ml_datafeeds</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html</a>
/// </summary>
public Task<CatResponse<CatDatafeedsRecord>> DatafeedsAsync(ICatDatafeedsRequest request, CancellationToken ct = default) => DoCatAsync<ICatDatafeedsRequest, CatDatafeedsRequestParameters, CatDatafeedsRecord>(request, ct);
/// <summary>
/// <c>GET</c> request to the <c>cat.ml_jobs</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-anomaly-detectors.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-anomaly-detectors.html</a>
Expand Down
77 changes: 77 additions & 0 deletions src/Nest/Requests.Cat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,83 @@ public bool? Verbose
}
}

[InterfaceDataContract]
public partial interface ICatDatafeedsRequest : IRequest<CatDatafeedsRequestParameters>
{
[IgnoreDataMember]
Id DatafeedId
{
get;
}
}

///<summary>Request for Datafeeds <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html</para></summary>
public partial class CatDatafeedsRequest : PlainRequestBase<CatDatafeedsRequestParameters>, ICatDatafeedsRequest
{
protected ICatDatafeedsRequest Self => this;
internal override ApiUrls ApiUrls => ApiUrlsLookups.CatDatafeeds;
///<summary>/_cat/ml/datafeeds</summary>
public CatDatafeedsRequest(): base()
{
}

///<summary>/_cat/ml/datafeeds/{datafeed_id}</summary>
///<param name = "datafeedId">Optional, accepts null</param>
public CatDatafeedsRequest(Id datafeedId): base(r => r.Optional("datafeed_id", datafeedId))
{
}

// values part of the url path
[IgnoreDataMember]
Id ICatDatafeedsRequest.DatafeedId => Self.RouteValues.Get<Id>("datafeed_id");
// Request parameters
///<summary>Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)</summary>
public bool? AllowNoDatafeeds
{
get => Q<bool? >("allow_no_datafeeds");
set => Q("allow_no_datafeeds", value);
}

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

///<summary>Comma-separated list of column names to display</summary>
public string[] Headers
{
get => Q<string[]>("h");
set => Q("h", value);
}

///<summary>Return help information</summary>
public bool? Help
{
get => Q<bool? >("help");
set => Q("help", value);
}

///<summary>Comma-separated list of column names or column aliases to sort by</summary>
public string[] SortByColumns
{
get => Q<string[]>("s");
set => Q("s", value);
}

///<summary>Verbose mode. Display column headers</summary>
public bool? Verbose
{
get => Q<bool? >("v");
set => Q("v", value);
}
}

[InterfaceDataContract]
public partial interface ICatJobsRequest : IRequest<CatJobsRequestParameters>
{
Expand Down
15 changes: 15 additions & 0 deletions src/Nest/XPack/MachineLearning/Datafeed/DatafeedState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,33 @@

namespace Nest
{
/// <summary>
/// The status of the datafeed
/// </summary>
[StringEnum]
public enum DatafeedState
{
/// <summary>
/// The datafeed is actively receiving data.
/// </summary>
[EnumMember(Value = "started")]
Started,

/// <summary>
/// The datafeed is stopped and will not receive data until it is re-started.
/// </summary>
[EnumMember(Value = "stopped")]
Stopped,

/// <summary>
/// The datafeed has been requested to start but has not yet started.
/// </summary>
[EnumMember(Value = "starting")]
Starting,

/// <summary>
/// The datafeed has been requested to stop gracefully and is completing its final action.
/// </summary>
[EnumMember(Value = "stopping")]
Stopping
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nest/_Generated/ApiUrlsLookup.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal static class ApiUrlsLookups
internal static ApiUrls CatIndices = new ApiUrls(new[]{"_cat/indices", "_cat/indices/{index}"});
internal static ApiUrls CatMaster = new ApiUrls(new[]{"_cat/master"});
internal static ApiUrls CatMlDataFrameAnalytics = new ApiUrls(new[]{"_cat/ml/data_frame/analytics", "_cat/ml/data_frame/analytics/{id}"});
internal static ApiUrls CatMlDatafeeds = new ApiUrls(new[]{"_cat/ml/datafeeds", "_cat/ml/datafeeds/{datafeed_id}"});
internal static ApiUrls CatDatafeeds = new ApiUrls(new[]{"_cat/ml/datafeeds", "_cat/ml/datafeeds/{datafeed_id}"});
internal static ApiUrls CatJobs = new ApiUrls(new[]{"_cat/ml/anomaly_detectors", "_cat/ml/anomaly_detectors/{job_id}"});
internal static ApiUrls CatTrainedModels = new ApiUrls(new[]{"_cat/ml/trained_models", "_cat/ml/trained_models/{model_id}"});
internal static ApiUrls CatNodeAttributes = new ApiUrls(new[]{"_cat/nodeattrs"});
Expand Down
41 changes: 41 additions & 0 deletions tests/Tests/Cat/CatDatafeeds/CatDatafeedsApiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Elastic.Xunit.XunitPlumbing;
using Elasticsearch.Net;
using Nest;
using Tests.Core.Extensions;
using Tests.Framework.EndpointTests.TestState;
using Tests.XPack.MachineLearning;

namespace Tests.Cat.CatDatafeeds
{
[SkipVersion("<7.7.0", "Introduced in 7.7.0")]
public class CatDatafeedsApiTests
: MachineLearningIntegrationTestBase<CatResponse<CatDatafeedsRecord>, ICatDatafeedsRequest, CatDatafeedsDescriptor,
CatDatafeedsRequest>
{
public CatDatafeedsApiTests(MachineLearningCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
{
foreach (var callUniqueValue in values)
{
PutJob(client, callUniqueValue.Value);
OpenJob(client, callUniqueValue.Value);
PutDatafeed(client, callUniqueValue.Value);
}
}

protected override bool ExpectIsValid => true;
protected override int ExpectStatusCode => 200;
protected override HttpMethod HttpMethod => HttpMethod.GET;
protected override string UrlPath => "/_cat/ml/datafeeds";

protected override LazyResponses ClientUsage() => Calls(
(client, f) => client.Cat.Datafeeds(),
(client, f) => client.Cat.DatafeedsAsync(),
(client, r) => client.Cat.Datafeeds(r),
(client, r) => client.Cat.DatafeedsAsync(r)
);

protected override void ExpectResponse(CatResponse<CatDatafeedsRecord> response) => response.ShouldBeValid();
}
}
Loading