From d64018f8e1615d79763f39f2d48af6105398dc1a Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Mon, 26 Aug 2019 14:18:00 -0500 Subject: [PATCH] [ML] add supported types to no fields error message (#45926) (#45987) * [ML] add supported types to no fields error message * adding supported types to logger debug --- .../extractor/ExtractedFieldsDetector.java | 16 +++++++++++++--- .../extractor/ExtractedFieldsDetectorTests.java | 12 ++++++++---- 2 files changed, 21 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 017b7070fcd..61196110959 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,9 @@ public class ExtractedFieldsDetector { checkRequiredFieldsArePresent(fields); if (fields.isEmpty()) { - throw ExceptionsHelper.badRequestException("No compatible fields could be detected in index {}", Arrays.toString(index)); + throw ExceptionsHelper.badRequestException("No compatible fields could be detected in index {}. Supported types are {}.", + Arrays.toString(index), + getSupportedTypes()); } List sortedFields = new ArrayList<>(fields); @@ -143,14 +145,22 @@ public class ExtractedFieldsDetector { } 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) { 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 6d51923f68c..5fb752ffc80 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 class ExtractedFieldsDetectorTests extends ESTestCase { 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 class ExtractedFieldsDetectorTests extends ESTestCase { 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 class ExtractedFieldsDetectorTests extends ESTestCase { 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 class ExtractedFieldsDetectorTests extends ESTestCase { 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() {