From 3418e277fb61312526bf6b06ee145f7cbc2512ba Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Thu, 8 Apr 2021 15:12:55 +0100 Subject: [PATCH] Fix up incorrectly removed endpoint in 7.11 --- .../Configuration/CodeConfiguration.cs | 4 - src/Elasticsearch.Net/Api/Enums.Generated.cs | 31 ++++++ .../RequestParameters.MachineLearning.cs | 104 ++++++++++++++++++ .../ElasticLowLevelClient.MachineLearning.cs | 13 +++ tests/Tests.YamlRunner/SkipList.fs | 3 - 5 files changed, 148 insertions(+), 7 deletions(-) diff --git a/src/ApiGenerator/Configuration/CodeConfiguration.cs b/src/ApiGenerator/Configuration/CodeConfiguration.cs index 66bbc17c4ed..c9c83f26f91 100644 --- a/src/ApiGenerator/Configuration/CodeConfiguration.cs +++ b/src/ApiGenerator/Configuration/CodeConfiguration.cs @@ -31,10 +31,6 @@ public static class CodeConfiguration // To be removed "indices.upgrade.json", "indices.get_upgrade.json", - - // This was added in 7.12.0 BC1 but the spec was removed before GA, but the API still existed. - // This isn't the preferred API so skipping code gen for it. - "ml.find_file_structure.json" }; private static string[] IgnoredApisHighLevel { get; } = diff --git a/src/Elasticsearch.Net/Api/Enums.Generated.cs b/src/Elasticsearch.Net/Api/Enums.Generated.cs index 6642ac9bf71..e94851cd175 100644 --- a/src/Elasticsearch.Net/Api/Enums.Generated.cs +++ b/src/Elasticsearch.Net/Api/Enums.Generated.cs @@ -411,6 +411,19 @@ public enum IndicesShardStoresStatus All } + [StringEnum] + public enum MachineLearningFindFileStructureFormat + { + [EnumMember(Value = "ndjson")] + Ndjson, + [EnumMember(Value = "xml")] + Xml, + [EnumMember(Value = "delimited")] + Delimited, + [EnumMember(Value = "semi_structured_text")] + SemiStructuredText + } + [StringEnum] public enum ThreadType { @@ -461,6 +474,7 @@ static KnownEnums() EnumStringResolvers.TryAdd(typeof(Conflicts), (e) => GetStringValue((Conflicts)e)); EnumStringResolvers.TryAdd(typeof(OpType), (e) => GetStringValue((OpType)e)); EnumStringResolvers.TryAdd(typeof(IndicesShardStoresStatus), (e) => GetStringValue((IndicesShardStoresStatus)e)); + EnumStringResolvers.TryAdd(typeof(MachineLearningFindFileStructureFormat), (e) => GetStringValue((MachineLearningFindFileStructureFormat)e)); EnumStringResolvers.TryAdd(typeof(ThreadType), (e) => GetStringValue((ThreadType)e)); EnumStringResolvers.TryAdd(typeof(GroupBy), (e) => GetStringValue((GroupBy)e)); } @@ -933,6 +947,23 @@ public static string GetStringValue(this IndicesShardStoresStatus enumValue) throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'IndicesShardStoresStatus'"); } + public static string GetStringValue(this MachineLearningFindFileStructureFormat enumValue) + { + switch (enumValue) + { + case MachineLearningFindFileStructureFormat.Ndjson: + return "ndjson"; + case MachineLearningFindFileStructureFormat.Xml: + return "xml"; + case MachineLearningFindFileStructureFormat.Delimited: + return "delimited"; + case MachineLearningFindFileStructureFormat.SemiStructuredText: + return "semi_structured_text"; + } + + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'MachineLearningFindFileStructureFormat'"); + } + public static string GetStringValue(this ThreadType enumValue) { switch (enumValue) diff --git a/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.MachineLearning.cs b/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.MachineLearning.cs index b0984831e8d..cd2d921e8e2 100644 --- a/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.MachineLearning.cs +++ b/src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.MachineLearning.cs @@ -215,6 +215,110 @@ public class ExplainDataFrameAnalyticsRequestParameters : RequestParameters true; } + ///Request options for FindFileStructure https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-find-file-structure.html + public class FindFileStructureRequestParameters : RequestParameters + { + public override HttpMethod DefaultHttpMethod => HttpMethod.POST; + public override bool SupportsBody => true; + ///Optional parameter to specify the character set of the file + public string Charset + { + get => Q("charset"); + set => Q("charset", value); + } + + ///Optional parameter containing a comma separated list of the column names for a delimited file + public string[] ColumnNames + { + get => Q("column_names"); + set => Q("column_names", value); + } + + ///Optional parameter to specify the delimiter character for a delimited file - must be a single character + public string Delimiter + { + get => Q("delimiter"); + set => Q("delimiter", value); + } + + ///Whether to include a commentary on how the structure was derived + public bool? Explain + { + get => Q("explain"); + set => Q("explain", value); + } + + ///Optional parameter to specify the high level file format + public MachineLearningFindFileStructureFormat? MachineLearningFindFileStructureFormat + { + get => Q("format"); + set => Q("format", value); + } + + ///Optional parameter to specify the Grok pattern that should be used to extract fields from messages in a semi-structured text file + public string GrokPattern + { + get => Q("grok_pattern"); + set => Q("grok_pattern", value); + } + + ///Optional parameter to specify whether a delimited file includes the column names in its first row + public bool? HasHeaderRow + { + get => Q("has_header_row"); + set => Q("has_header_row", value); + } + + ///Maximum number of characters permitted in a single message when lines are merged to create messages. + public int? LineMergeSizeLimit + { + get => Q("line_merge_size_limit"); + set => Q("line_merge_size_limit", value); + } + + ///How many lines of the file should be included in the analysis + public int? LinesToSample + { + get => Q("lines_to_sample"); + set => Q("lines_to_sample", value); + } + + ///Optional parameter to specify the quote character for a delimited file - must be a single character + public string Quote + { + get => Q("quote"); + set => Q("quote", value); + } + + ///Optional parameter to specify whether the values between delimiters in a delimited file should have whitespace trimmed from them + public bool? ShouldTrimFields + { + get => Q("should_trim_fields"); + set => Q("should_trim_fields", value); + } + + ///Timeout after which the analysis will be aborted + public TimeSpan Timeout + { + get => Q("timeout"); + set => Q("timeout", value); + } + + ///Optional parameter to specify the timestamp field in the file + public string TimestampField + { + get => Q("timestamp_field"); + set => Q("timestamp_field", value); + } + + ///Optional parameter to specify the timestamp format in the file - may be either a Joda or Java time format + public string TimestampFormat + { + get => Q("timestamp_format"); + set => Q("timestamp_format", value); + } + } + ///Request options for FlushJob https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-flush-job.html public class FlushJobRequestParameters : RequestParameters { diff --git a/src/Elasticsearch.Net/ElasticLowLevelClient.MachineLearning.cs b/src/Elasticsearch.Net/ElasticLowLevelClient.MachineLearning.cs index 081fcf85b4a..a58b50a629f 100644 --- a/src/Elasticsearch.Net/ElasticLowLevelClient.MachineLearning.cs +++ b/src/Elasticsearch.Net/ElasticLowLevelClient.MachineLearning.cs @@ -254,6 +254,19 @@ public TResponse ExplainDataFrameAnalytics(string id, PostData body, [MapsApi("ml.explain_data_frame_analytics", "id, body")] public Task ExplainDataFrameAnalyticsAsync(string id, PostData body, ExplainDataFrameAnalyticsRequestParameters requestParameters = null, CancellationToken ctx = default) where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync(POST, Url($"_ml/data_frame/analytics/{id:id}/_explain"), ctx, body, RequestParams(requestParameters)); + ///POST on /_ml/find_file_structure https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-find-file-structure.html + ///The contents of the file to be analyzed + ///Request specific configuration such as querystring parameters & request specific connection settings. + ///Note: Experimental within the Elasticsearch server, this functionality is Experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features. This functionality is subject to potential breaking changes within a minor version, meaning that your referencing code may break when this library is upgraded. + public TResponse FindFileStructure(PostData body, FindFileStructureRequestParameters requestParameters = null) + where TResponse : class, IElasticsearchResponse, new() => DoRequest(POST, "_ml/find_file_structure", body, RequestParams(requestParameters)); + ///POST on /_ml/find_file_structure https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-find-file-structure.html + ///The contents of the file to be analyzed + ///Request specific configuration such as querystring parameters & request specific connection settings. + ///Note: Experimental within the Elasticsearch server, this functionality is Experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features. This functionality is subject to potential breaking changes within a minor version, meaning that your referencing code may break when this library is upgraded. + [MapsApi("ml.find_file_structure", "body")] + public Task FindFileStructureAsync(PostData body, FindFileStructureRequestParameters requestParameters = null, CancellationToken ctx = default) + where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync(POST, "_ml/find_file_structure", ctx, body, RequestParams(requestParameters)); ///POST on /_ml/anomaly_detectors/{job_id}/_flush https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-flush-job.html ///The name of the job to flush ///Flush parameters diff --git a/tests/Tests.YamlRunner/SkipList.fs b/tests/Tests.YamlRunner/SkipList.fs index 3c5f59da051..017d1735718 100644 --- a/tests/Tests.YamlRunner/SkipList.fs +++ b/tests/Tests.YamlRunner/SkipList.fs @@ -182,7 +182,4 @@ let SkipList = dict [ // TODO investigate post 7.11.0 SkipFile "nodes.info/10_basic.yml", Section "node_info role test" - ] - -