diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/DetectionRule.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/DetectionRule.java index a2f71f611f4..0948e978c88 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/DetectionRule.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/DetectionRule.java @@ -251,7 +251,7 @@ public class DetectionRule implements ToXContentObject, Writeable { throw ExceptionsHelper.badRequestException(msg); } for (RuleCondition condition : conditions) { - if (condition.getType() == RuleConditionType.CATEGORICAL && targetFieldName != null) { + if (condition.getType().isCategorical() && targetFieldName != null) { String msg = Messages.getMessage(Messages.JOB_CONFIG_DETECTION_RULE_CONDITION_CATEGORICAL_INVALID_OPTION, DetectionRule.TARGET_FIELD_NAME_FIELD.getPreferredName()); throw ExceptionsHelper.badRequestException(msg); diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/Detector.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/Detector.java index f1a42fa2b7e..e5cf4b16f6e 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/Detector.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/Detector.java @@ -698,6 +698,7 @@ public class Detector implements ToXContentObject, Writeable { List validOptions = Collections.emptyList(); switch (condition.getType()) { case CATEGORICAL: + case CATEGORICAL_COMPLEMENT: validOptions = extractAnalysisFields(); break; case NUMERICAL_ACTUAL: diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/RuleCondition.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/RuleCondition.java index 3b406e3ec34..6ca24c518d8 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/RuleCondition.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/RuleCondition.java @@ -197,6 +197,7 @@ public class RuleCondition implements ToXContentObject, Writeable { private static void verifyFieldsBoundToType(RuleCondition ruleCondition) throws ElasticsearchParseException { switch (ruleCondition.getType()) { case CATEGORICAL: + case CATEGORICAL_COMPLEMENT: verifyCategorical(ruleCondition); break; case NUMERICAL_ACTUAL: diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/RuleConditionType.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/RuleConditionType.java index 2ddd0dac2cd..aa563d001b5 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/RuleConditionType.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/RuleConditionType.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.core.ml.job.config; +import org.elasticsearch.Version; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -14,22 +15,29 @@ import java.io.IOException; import java.util.Locale; public enum RuleConditionType implements Writeable { - CATEGORICAL(false), - NUMERICAL_ACTUAL(true), - NUMERICAL_TYPICAL(true), - NUMERICAL_DIFF_ABS(true), - TIME(false); + CATEGORICAL(false, true), + NUMERICAL_ACTUAL(true, false), + NUMERICAL_TYPICAL(true, false), + NUMERICAL_DIFF_ABS(true, false), + TIME(false, false), + CATEGORICAL_COMPLEMENT(false, true); private final boolean isNumerical; + private final boolean isCategorical; - RuleConditionType(boolean isNumerical) { + RuleConditionType(boolean isNumerical, boolean isCategorical) { this.isNumerical = isNumerical; + this.isCategorical = isCategorical; } public boolean isNumerical() { return isNumerical; } + public boolean isCategorical() { + return isCategorical; + } + /** * Case-insensitive from string method. * @@ -47,7 +55,11 @@ public enum RuleConditionType implements Writeable { @Override public void writeTo(StreamOutput out) throws IOException { - out.writeEnum(this); + if (this == CATEGORICAL_COMPLEMENT && out.getVersion().before(Version.V_6_3_0)) { + out.writeEnum(CATEGORICAL); + } else { + out.writeEnum(this); + } } @Override diff --git a/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/config/RuleConditionTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/config/RuleConditionTests.java index 62d174c05da..882c590983a 100644 --- a/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/config/RuleConditionTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/config/RuleConditionTests.java @@ -19,25 +19,22 @@ public class RuleConditionTests extends AbstractSerializingTestCase