From e090176f17867c8c9a04986ebc1b3516d63d0dc2 Mon Sep 17 00:00:00 2001 From: Iana Bondarska Date: Wed, 17 Apr 2019 17:01:46 +0200 Subject: [PATCH] [ML] Exclude analysis fields with core field names from anomaly results (#41093) Added "_index", "_type", "_id" to list of reserved fields. Closes #39406 --- .../core/ml/job/results/ReservedFieldNames.java | 15 ++++++++++++--- .../persistence/ElasticsearchMappingsTests.java | 9 +++++++++ .../ml/job/results/ReservedFieldNamesTests.java | 6 +++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/ReservedFieldNames.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/ReservedFieldNames.java index 333b87b0c29..51bdc5ce594 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/ReservedFieldNames.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/ReservedFieldNames.java @@ -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 }; /** diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappingsTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappingsTests.java index f5461a1abf3..42e328e3591 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappingsTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappingsTests.java @@ -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 INTERNAL_FIELDS = Arrays.asList( + GetResult._ID, + GetResult._INDEX, + GetResult._TYPE + ); + public void testResultsMapppingReservedFields() throws Exception { Set overridden = new HashSet<>(KEYWORDS); @@ -76,6 +83,7 @@ public class ElasticsearchMappingsTests extends ESTestCase { Set 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 expected = collectConfigDocFieldNames(); expected.removeAll(overridden); + expected.addAll(INTERNAL_FIELDS); compareFields(expected, ReservedFieldNames.RESERVED_CONFIG_FIELD_NAMES); } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/results/ReservedFieldNamesTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/results/ReservedFieldNamesTests.java index a08b53fba3c..d594404e9c2 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/results/ReservedFieldNamesTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/results/ReservedFieldNamesTests.java @@ -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)); } -} \ No newline at end of file +}