Skip to content

Commit cf651ec

Browse files
authored
[ML] add supported types to no fields error message (#45926)
* [ML] add supported types to no fields error message * adding supported types to logger debug
1 parent 527334d commit cf651ec

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetector.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ public ExtractedFields detect() {
8484
checkRequiredFieldsArePresent(fields);
8585

8686
if (fields.isEmpty()) {
87-
throw ExceptionsHelper.badRequestException("No compatible fields could be detected in index {}", Arrays.toString(index));
87+
throw ExceptionsHelper.badRequestException("No compatible fields could be detected in index {}. Supported types are {}.",
88+
Arrays.toString(index),
89+
getSupportedTypes());
8890
}
8991

9092
List<String> sortedFields = new ArrayList<>(fields);
@@ -143,14 +145,22 @@ private void removeFieldsWithIncompatibleTypes(Set<String> fields) {
143145
} else if (config.getAnalysis().supportsCategoricalFields() && CATEGORICAL_TYPES.containsAll(fieldTypes)) {
144146
LOGGER.debug("[{}] field [{}] is compatible as it is categorical", config.getId(), field);
145147
} else {
146-
LOGGER.debug("[{}] Removing field [{}] because its types are not supported; types {}",
147-
config.getId(), field, fieldTypes);
148+
LOGGER.debug("[{}] Removing field [{}] because its types are not supported; types {}; supported {}",
149+
config.getId(), field, fieldTypes, getSupportedTypes());
148150
fieldsIterator.remove();
149151
}
150152
}
151153
}
152154
}
153155

156+
private Set<String> getSupportedTypes() {
157+
Set<String> supportedTypes = new HashSet<>(NUMERICAL_TYPES);
158+
if (config.getAnalysis().supportsCategoricalFields()) {
159+
supportedTypes.addAll(CATEGORICAL_TYPES);
160+
}
161+
return supportedTypes;
162+
}
163+
154164
private void includeAndExcludeFields(Set<String> fields) {
155165
FetchSourceContext analyzedFields = config.getAnalyzedFields();
156166
if (analyzedFields == null) {

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetectorTests.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public void testDetect_GivenNonNumericField() {
7575
SOURCE_INDEX, buildOutlierDetectionConfig(), RESULTS_FIELD, false, 100, fieldCapabilities);
7676
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> extractedFieldsDetector.detect());
7777

78-
assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]"));
78+
assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]." +
79+
" Supported types are [scaled_float, double, byte, short, half_float, integer, float, long]."));
7980
}
8081

8182
public void testDetect_GivenOutlierDetectionAndFieldWithNumericAndNonNumericTypes() {
@@ -86,7 +87,8 @@ public void testDetect_GivenOutlierDetectionAndFieldWithNumericAndNonNumericType
8687
SOURCE_INDEX, buildOutlierDetectionConfig(), RESULTS_FIELD, false, 100, fieldCapabilities);
8788
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> extractedFieldsDetector.detect());
8889

89-
assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]"));
90+
assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]. " +
91+
"Supported types are [scaled_float, double, byte, short, half_float, integer, float, long]."));
9092
}
9193

9294
public void testDetect_GivenOutlierDetectionAndMultipleFields() {
@@ -150,7 +152,8 @@ public void testDetect_GivenIgnoredField() {
150152
SOURCE_INDEX, buildOutlierDetectionConfig(), RESULTS_FIELD, false, 100, fieldCapabilities);
151153
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> extractedFieldsDetector.detect());
152154

153-
assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]"));
155+
assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]. " +
156+
"Supported types are [scaled_float, double, byte, short, half_float, integer, float, long]."));
154157
}
155158

156159
public void testDetect_ShouldSortFieldsAlphabetically() {
@@ -203,7 +206,8 @@ public void testDetectedExtractedFields_GivenExcludeAllValidFields() {
203206
ExtractedFieldsDetector extractedFieldsDetector = new ExtractedFieldsDetector(
204207
SOURCE_INDEX, buildOutlierDetectionConfig(desiredFields), RESULTS_FIELD, false, 100, fieldCapabilities);
205208
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> extractedFieldsDetector.detect());
206-
assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]"));
209+
assertThat(e.getMessage(), equalTo("No compatible fields could be detected in index [source_index]. " +
210+
"Supported types are [scaled_float, double, byte, short, half_float, integer, float, long]."));
207211
}
208212

209213
public void testDetectedExtractedFields_GivenInclusionsAndExclusions() {

0 commit comments

Comments
 (0)