From b9412a0fe790e59d0efdb6a56f4a850a00e0f5fe Mon Sep 17 00:00:00 2001 From: Benjamin Trent <4357155+benwtrent@users.noreply.github.com> Date: Fri, 23 Aug 2019 13:46:11 -0500 Subject: [PATCH 1/2] [ML] add supported types to no fields error message --- .../dataframe/extractor/ExtractedFieldsDetector.java | 8 +++++++- .../extractor/ExtractedFieldsDetectorTests.java | 12 ++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetector.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetector.java index 017b7070fcda2..2745f17d1f91f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetector.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetector.java @@ -84,7 +84,13 @@ public ExtractedFields detect() { checkRequiredFieldsArePresent(fields); if (fields.isEmpty()) { - throw ExceptionsHelper.badRequestException("No compatible fields could be detected in index {}", Arrays.toString(index)); + Set supportedTypes = new HashSet<>(NUMERICAL_TYPES); + if (config.getAnalysis().supportsCategoricalFields()) { + supportedTypes.addAll(CATEGORICAL_TYPES); + } + throw ExceptionsHelper.badRequestException("No compatible fields could be detected in index {}. Supported types are {}.", + Arrays.toString(index), + supportedTypes); } List sortedFields = new ArrayList<>(fields); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetectorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetectorTests.java index 6d51923f68c75..5fb752ffc80c5 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetectorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetectorTests.java @@ -75,7 +75,8 @@ public void testDetect_GivenNonNumericField() { SOURCE_INDEX, buildOutlierDetectionConfig(), RESULTS_FIELD, false, 100, fieldCapabilities); ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> extractedFieldsDetector.detect()); - assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]")); + assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]." + + " Supported types are [scaled_float, double, byte, short, half_float, integer, float, long].")); } public void testDetect_GivenOutlierDetectionAndFieldWithNumericAndNonNumericTypes() { @@ -86,7 +87,8 @@ public void testDetect_GivenOutlierDetectionAndFieldWithNumericAndNonNumericType SOURCE_INDEX, buildOutlierDetectionConfig(), RESULTS_FIELD, false, 100, fieldCapabilities); ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> extractedFieldsDetector.detect()); - assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]")); + assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]. " + + "Supported types are [scaled_float, double, byte, short, half_float, integer, float, long].")); } public void testDetect_GivenOutlierDetectionAndMultipleFields() { @@ -150,7 +152,8 @@ public void testDetect_GivenIgnoredField() { SOURCE_INDEX, buildOutlierDetectionConfig(), RESULTS_FIELD, false, 100, fieldCapabilities); ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> extractedFieldsDetector.detect()); - assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]")); + assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]. " + + "Supported types are [scaled_float, double, byte, short, half_float, integer, float, long].")); } public void testDetect_ShouldSortFieldsAlphabetically() { @@ -203,7 +206,8 @@ public void testDetectedExtractedFields_GivenExcludeAllValidFields() { ExtractedFieldsDetector extractedFieldsDetector = new ExtractedFieldsDetector( SOURCE_INDEX, buildOutlierDetectionConfig(desiredFields), RESULTS_FIELD, false, 100, fieldCapabilities); ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> extractedFieldsDetector.detect()); - assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]")); + assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]. " + + "Supported types are [scaled_float, double, byte, short, half_float, integer, float, long].")); } public void testDetectedExtractedFields_GivenInclusionsAndExclusions() { From 6bcdabe6abd491dd7d338f71f4c4112f28f4ae38 Mon Sep 17 00:00:00 2001 From: Benjamin Trent <4357155+benwtrent@users.noreply.github.com> Date: Mon, 26 Aug 2019 08:29:26 -0500 Subject: [PATCH 2/2] adding supported types to logger debug --- .../extractor/ExtractedFieldsDetector.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetector.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetector.java index 2745f17d1f91f..6119611095989 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetector.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetector.java @@ -84,13 +84,9 @@ public ExtractedFields detect() { checkRequiredFieldsArePresent(fields); if (fields.isEmpty()) { - Set supportedTypes = new HashSet<>(NUMERICAL_TYPES); - if (config.getAnalysis().supportsCategoricalFields()) { - supportedTypes.addAll(CATEGORICAL_TYPES); - } throw ExceptionsHelper.badRequestException("No compatible fields could be detected in index {}. Supported types are {}.", Arrays.toString(index), - supportedTypes); + getSupportedTypes()); } List sortedFields = new ArrayList<>(fields); @@ -149,14 +145,22 @@ private void removeFieldsWithIncompatibleTypes(Set fields) { } else if (config.getAnalysis().supportsCategoricalFields() && CATEGORICAL_TYPES.containsAll(fieldTypes)) { LOGGER.debug("[{}] field [{}] is compatible as it is categorical", config.getId(), field); } else { - LOGGER.debug("[{}] Removing field [{}] because its types are not supported; types {}", - config.getId(), field, fieldTypes); + LOGGER.debug("[{}] Removing field [{}] because its types are not supported; types {}; supported {}", + config.getId(), field, fieldTypes, getSupportedTypes()); fieldsIterator.remove(); } } } } + private Set getSupportedTypes() { + Set supportedTypes = new HashSet<>(NUMERICAL_TYPES); + if (config.getAnalysis().supportsCategoricalFields()) { + supportedTypes.addAll(CATEGORICAL_TYPES); + } + return supportedTypes; + } + private void includeAndExcludeFields(Set fields) { FetchSourceContext analyzedFields = config.getAnalyzedFields(); if (analyzedFields == null) {