diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Verifier.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Verifier.java index a62fd312376ee..30e3229ca8c1b 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Verifier.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Verifier.java @@ -780,14 +780,14 @@ private static void checkFullTextSearchDisjunctions( Set failures ) { condition.forEachUp(Or.class, or -> { - boolean left = checkFullTextSearchInDisjunctions(or.left()); - boolean right = checkFullTextSearchInDisjunctions(or.right()); + boolean left = onlyFullTextFunctionsInExpression(or.left()); + boolean right = onlyFullTextFunctionsInExpression(or.right()); if (left ^ right) { Holder elementName = new Holder<>(); if (left) { - or.right().forEachDown(FullTextFunction.class, ftf -> elementName.set(typeNameProvider.apply(ftf))); - } else { or.left().forEachDown(FullTextFunction.class, ftf -> elementName.set(typeNameProvider.apply(ftf))); + } else { + or.right().forEachDown(FullTextFunction.class, ftf -> elementName.set(typeNameProvider.apply(ftf))); } failures.add( fail( @@ -805,22 +805,22 @@ private static void checkFullTextSearchDisjunctions( /** * Checks whether an expression contains just full text functions or negations (NOT) and combinations (AND, OR) of full text functions * - * @param expression parent expression to add to the failure message + * @param expression expression to check * @return true if all children are full text functions or negations of full text functions, false otherwise */ - private static boolean checkFullTextSearchInDisjunctions(Expression expression) { + private static boolean onlyFullTextFunctionsInExpression(Expression expression) { if (expression instanceof FullTextFunction) { - return false; + return true; } else if (expression instanceof Not || expression instanceof BinaryLogic) { for (Expression child : expression.children()) { - if (checkFullTextSearchInDisjunctions(child)) { - return true; + if (onlyFullTextFunctionsInExpression(child) == false) { + return false; } } - return false; + return true; } - return true; + return false; } /** diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java index c82dcdda60900..cc866804c1951 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java @@ -1168,14 +1168,14 @@ public void testMatchInsideEval() throws Exception { public void testMatchFilter() throws Exception { assertEquals( "1:19: Invalid condition [first_name:\"Anna\" or starts_with(first_name, \"Anne\")]. " - + "[:] operator can be used as part of an OR condition, " + - "but only if other full text functions are used as part of the condition", + + "[:] operator can be used as part of an OR condition, " + + "but only if other full text functions are used as part of the condition", error("from test | where first_name:\"Anna\" or starts_with(first_name, \"Anne\")") ); assertEquals( - "1:51: Invalid condition [first_name:\"Anna\" OR new_salary > 100]. [:] operator can be used as part of an OR " + - "condition, but only if other full text functions are used as part of the condition", + "1:51: Invalid condition [first_name:\"Anna\" OR new_salary > 100]. [:] operator can be used as part of an OR " + + "condition, but only if other full text functions are used as part of the condition", error("from test | eval new_salary = salary + 10 | where first_name:\"Anna\" OR new_salary > 100") ); }