Skip to content

Commit

Permalink
[ML] Exclude analysis fields with core field names from anomaly resul…
Browse files Browse the repository at this point in the history
…ts (elastic#41093)

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

Closes elastic#39406
  • Loading branch information
yana2301 authored and Gurkan Kaymak committed May 27, 2019
1 parent bb1239e commit 2dde1c0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -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);

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

Set<String> expected = collectResultsDocFieldNames();
expected.removeAll(overridden);
expected.addAll(INTERNAL_FIELDS);

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

Set<String> expected = collectConfigDocFieldNames();
expected.removeAll(overridden);
expected.addAll(INTERNAL_FIELDS);

compareFields(expected, ReservedFieldNames.RESERVED_CONFIG_FIELD_NAMES);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,5 +17,8 @@ public void testIsValidFieldName() {
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));
}
}
}

0 comments on commit 2dde1c0

Please sign in to comment.