Skip to content

Commit

Permalink
[ML] add supported types to no fields error message (#45926)
Browse files Browse the repository at this point in the history
* [ML] add supported types to no fields error message

* adding supported types to logger debug
  • Loading branch information
benwtrent authored Aug 26, 2019
1 parent 527334d commit cf651ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public ExtractedFields detect() {
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<String> sortedFields = new ArrayList<>(fields);
Expand Down Expand Up @@ -143,14 +145,22 @@ private void removeFieldsWithIncompatibleTypes(Set<String> 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<String> getSupportedTypes() {
Set<String> supportedTypes = new HashSet<>(NUMERICAL_TYPES);
if (config.getAnalysis().supportsCategoricalFields()) {
supportedTypes.addAll(CATEGORICAL_TYPES);
}
return supportedTypes;
}

private void includeAndExcludeFields(Set<String> fields) {
FetchSourceContext analyzedFields = config.getAnalyzedFields();
if (analyzedFields == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit cf651ec

Please sign in to comment.