[ML] Exclude analysis fields with core field names from anomaly results (#41093)

Added "_index", "_type", "_id" to list of reserved fields.

Closes #39406
This commit is contained in:
Iana Bondarska 2019-04-17 17:01:46 +02:00 committed by David Roberts
parent 2ee87c99d9
commit e090176f17
3 changed files with 26 additions and 4 deletions

View File

@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.core.ml.job.results;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.xpack.core.ml.datafeed.ChunkingConfig;
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
import org.elasticsearch.xpack.core.ml.datafeed.DelayedDataCheckConfig;
@ -171,8 +172,12 @@ public final class ReservedFieldNames {
Result.RESULT_TYPE.getPreferredName(),
Result.TIMESTAMP.getPreferredName(),
Result.IS_INTERIM.getPreferredName()
};
Result.IS_INTERIM.getPreferredName(),
GetResult._ID,
GetResult._INDEX,
GetResult._TYPE
};
/**
* This array should be updated to contain all the field names that appear
@ -256,7 +261,11 @@ public final class ReservedFieldNames {
ChunkingConfig.MODE_FIELD.getPreferredName(),
ChunkingConfig.TIME_SPAN_FIELD.getPreferredName(),
ElasticsearchMappings.CONFIG_TYPE
ElasticsearchMappings.CONFIG_TYPE,
GetResult._ID,
GetResult._INDEX,
GetResult._TYPE
};
/**

View File

@ -19,6 +19,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
@ -63,6 +64,12 @@ public class ElasticsearchMappingsTests extends ESTestCase {
ElasticsearchMappings.WHITESPACE
);
private static List<String> INTERNAL_FIELDS = Arrays.asList(
GetResult._ID,
GetResult._INDEX,
GetResult._TYPE
);
public void testResultsMapppingReservedFields() throws Exception {
Set<String> overridden = new HashSet<>(KEYWORDS);
@ -76,6 +83,7 @@ public class ElasticsearchMappingsTests extends ESTestCase {
Set<String> expected = collectResultsDocFieldNames();
expected.removeAll(overridden);
expected.addAll(INTERNAL_FIELDS);
compareFields(expected, ReservedFieldNames.RESERVED_RESULT_FIELD_NAMES);
}
@ -91,6 +99,7 @@ public class ElasticsearchMappingsTests extends ESTestCase {
Set<String> expected = collectConfigDocFieldNames();
expected.removeAll(overridden);
expected.addAll(INTERNAL_FIELDS);
compareFields(expected, ReservedFieldNames.RESERVED_CONFIG_FIELD_NAMES);
}

View File

@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.ml.job.results;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.ml.job.results.AnomalyRecord;
import org.elasticsearch.xpack.core.ml.job.results.ReservedFieldNames;
@ -16,5 +17,8 @@ public class ReservedFieldNamesTests extends ESTestCase {
assertTrue(ReservedFieldNames.isValidFieldName("host.actual"));
assertFalse(ReservedFieldNames.isValidFieldName("actual.host"));
assertFalse(ReservedFieldNames.isValidFieldName(AnomalyRecord.BUCKET_SPAN.getPreferredName()));
assertFalse(ReservedFieldNames.isValidFieldName(GetResult._INDEX));
assertFalse(ReservedFieldNames.isValidFieldName(GetResult._TYPE));
assertFalse(ReservedFieldNames.isValidFieldName(GetResult._ID));
}
}
}