[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
This commit is contained in:
Benjamin Trent 2019-08-26 14:18:00 -05:00 committed by GitHub
parent 5535ff0a44
commit d64018f8e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View File

@ -84,7 +84,9 @@ public class ExtractedFieldsDetector {
checkRequiredFieldsArePresent(fields); checkRequiredFieldsArePresent(fields);
if (fields.isEmpty()) { 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); List<String> sortedFields = new ArrayList<>(fields);
@ -143,14 +145,22 @@ public class ExtractedFieldsDetector {
} else if (config.getAnalysis().supportsCategoricalFields() && CATEGORICAL_TYPES.containsAll(fieldTypes)) { } else if (config.getAnalysis().supportsCategoricalFields() && CATEGORICAL_TYPES.containsAll(fieldTypes)) {
LOGGER.debug("[{}] field [{}] is compatible as it is categorical", config.getId(), field); LOGGER.debug("[{}] field [{}] is compatible as it is categorical", config.getId(), field);
} else { } else {
LOGGER.debug("[{}] Removing field [{}] because its types are not supported; types {}", LOGGER.debug("[{}] Removing field [{}] because its types are not supported; types {}; supported {}",
config.getId(), field, fieldTypes); config.getId(), field, fieldTypes, getSupportedTypes());
fieldsIterator.remove(); 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) { private void includeAndExcludeFields(Set<String> fields) {
FetchSourceContext analyzedFields = config.getAnalyzedFields(); FetchSourceContext analyzedFields = config.getAnalyzedFields();
if (analyzedFields == null) { if (analyzedFields == null) {

View File

@ -75,7 +75,8 @@ public class ExtractedFieldsDetectorTests extends ESTestCase {
SOURCE_INDEX, buildOutlierDetectionConfig(), RESULTS_FIELD, false, 100, fieldCapabilities); SOURCE_INDEX, buildOutlierDetectionConfig(), RESULTS_FIELD, false, 100, fieldCapabilities);
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> extractedFieldsDetector.detect()); 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() { public void testDetect_GivenOutlierDetectionAndFieldWithNumericAndNonNumericTypes() {
@ -86,7 +87,8 @@ public class ExtractedFieldsDetectorTests extends ESTestCase {
SOURCE_INDEX, buildOutlierDetectionConfig(), RESULTS_FIELD, false, 100, fieldCapabilities); SOURCE_INDEX, buildOutlierDetectionConfig(), RESULTS_FIELD, false, 100, fieldCapabilities);
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> extractedFieldsDetector.detect()); 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() { public void testDetect_GivenOutlierDetectionAndMultipleFields() {
@ -150,7 +152,8 @@ public class ExtractedFieldsDetectorTests extends ESTestCase {
SOURCE_INDEX, buildOutlierDetectionConfig(), RESULTS_FIELD, false, 100, fieldCapabilities); SOURCE_INDEX, buildOutlierDetectionConfig(), RESULTS_FIELD, false, 100, fieldCapabilities);
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> extractedFieldsDetector.detect()); 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() { public void testDetect_ShouldSortFieldsAlphabetically() {
@ -203,7 +206,8 @@ public class ExtractedFieldsDetectorTests extends ESTestCase {
ExtractedFieldsDetector extractedFieldsDetector = new ExtractedFieldsDetector( ExtractedFieldsDetector extractedFieldsDetector = new ExtractedFieldsDetector(
SOURCE_INDEX, buildOutlierDetectionConfig(desiredFields), RESULTS_FIELD, false, 100, fieldCapabilities); SOURCE_INDEX, buildOutlierDetectionConfig(desiredFields), RESULTS_FIELD, false, 100, fieldCapabilities);
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, () -> extractedFieldsDetector.detect()); 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() { public void testDetectedExtractedFields_GivenInclusionsAndExclusions() {