Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {}.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! We should also do the same for the last error message in removeFieldsWithIncompatibleTypes()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roger

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