Skip to content

Commit 05c1476

Browse files
yana2301David Roberts
authored andcommitted
[ML] Exclude analysis fields with core field names from anomaly results (#41093)
Added "_index", "_type", "_id" to list of reserved fields. Closes #39406
1 parent 4bd8e7b commit 05c1476

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/ReservedFieldNames.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.core.ml.job.results;
77

8+
import org.elasticsearch.index.get.GetResult;
89
import org.elasticsearch.xpack.core.ml.datafeed.ChunkingConfig;
910
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
1011
import org.elasticsearch.xpack.core.ml.datafeed.DelayedDataCheckConfig;
@@ -171,8 +172,12 @@ public final class ReservedFieldNames {
171172

172173
Result.RESULT_TYPE.getPreferredName(),
173174
Result.TIMESTAMP.getPreferredName(),
174-
Result.IS_INTERIM.getPreferredName()
175-
};
175+
Result.IS_INTERIM.getPreferredName(),
176+
177+
GetResult._ID,
178+
GetResult._INDEX,
179+
GetResult._TYPE
180+
};
176181

177182
/**
178183
* This array should be updated to contain all the field names that appear
@@ -256,7 +261,11 @@ public final class ReservedFieldNames {
256261
ChunkingConfig.MODE_FIELD.getPreferredName(),
257262
ChunkingConfig.TIME_SPAN_FIELD.getPreferredName(),
258263

259-
ElasticsearchMappings.CONFIG_TYPE
264+
ElasticsearchMappings.CONFIG_TYPE,
265+
266+
GetResult._ID,
267+
GetResult._INDEX,
268+
GetResult._TYPE
260269
};
261270

262271
/**

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappingsTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.common.settings.Settings;
2020
import org.elasticsearch.common.xcontent.XContentBuilder;
2121
import org.elasticsearch.common.xcontent.XContentParser;
22+
import org.elasticsearch.index.get.GetResult;
2223
import org.elasticsearch.test.ESTestCase;
2324
import org.elasticsearch.test.VersionUtils;
2425
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
@@ -63,6 +64,12 @@ public class ElasticsearchMappingsTests extends ESTestCase {
6364
ElasticsearchMappings.WHITESPACE
6465
);
6566

67+
private static List<String> INTERNAL_FIELDS = Arrays.asList(
68+
GetResult._ID,
69+
GetResult._INDEX,
70+
GetResult._TYPE
71+
);
72+
6673
public void testResultsMapppingReservedFields() throws Exception {
6774
Set<String> overridden = new HashSet<>(KEYWORDS);
6875

@@ -76,6 +83,7 @@ public void testResultsMapppingReservedFields() throws Exception {
7683

7784
Set<String> expected = collectResultsDocFieldNames();
7885
expected.removeAll(overridden);
86+
expected.addAll(INTERNAL_FIELDS);
7987

8088
compareFields(expected, ReservedFieldNames.RESERVED_RESULT_FIELD_NAMES);
8189
}
@@ -91,6 +99,7 @@ public void testConfigMapppingReservedFields() throws Exception {
9199

92100
Set<String> expected = collectConfigDocFieldNames();
93101
expected.removeAll(overridden);
102+
expected.addAll(INTERNAL_FIELDS);
94103

95104
compareFields(expected, ReservedFieldNames.RESERVED_CONFIG_FIELD_NAMES);
96105
}

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/results/ReservedFieldNamesTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.ml.job.results;
77

8+
import org.elasticsearch.index.get.GetResult;
89
import org.elasticsearch.test.ESTestCase;
910
import org.elasticsearch.xpack.core.ml.job.results.AnomalyRecord;
1011
import org.elasticsearch.xpack.core.ml.job.results.ReservedFieldNames;
@@ -16,5 +17,8 @@ public void testIsValidFieldName() {
1617
assertTrue(ReservedFieldNames.isValidFieldName("host.actual"));
1718
assertFalse(ReservedFieldNames.isValidFieldName("actual.host"));
1819
assertFalse(ReservedFieldNames.isValidFieldName(AnomalyRecord.BUCKET_SPAN.getPreferredName()));
20+
assertFalse(ReservedFieldNames.isValidFieldName(GetResult._INDEX));
21+
assertFalse(ReservedFieldNames.isValidFieldName(GetResult._TYPE));
22+
assertFalse(ReservedFieldNames.isValidFieldName(GetResult._ID));
1923
}
20-
}
24+
}

0 commit comments

Comments
 (0)