3232import org .elasticsearch .xpack .esql .core .type .DataType ;
3333import org .elasticsearch .xpack .esql .core .type .DataTypeConverter ;
3434import org .elasticsearch .xpack .esql .evaluator .mapper .EvaluatorMapper ;
35- import org .elasticsearch .xpack .esql .expression .function .aggregate .FilteredExpression ;
3635import org .elasticsearch .xpack .esql .expression .predicate .logical .BinaryLogic ;
3736import org .elasticsearch .xpack .esql .expression .predicate .logical .Not ;
3837import org .elasticsearch .xpack .esql .optimizer .rules .physical .local .LucenePushdownPredicates ;
@@ -228,7 +227,7 @@ private static void checkFullTextQueryFunctions(LogicalPlan plan, Failures failu
228227 );
229228 checkFullTextFunctionsParents (condition , failures );
230229 } else if (plan instanceof Aggregate agg ) {
231- agg . forEachExpression ( exp -> checkFullTextFunctionsInAggs (exp , failures ) );
230+ checkFullTextFunctionsInAggs (agg , failures );
232231 } else {
233232 plan .forEachExpression (FullTextFunction .class , ftf -> {
234233 failures .add (
@@ -238,19 +237,16 @@ private static void checkFullTextQueryFunctions(LogicalPlan plan, Failures failu
238237 }
239238 }
240239
241- private static void checkFullTextFunctionsInAggs (Expression expression , Failures failures ) {
242- if (expression instanceof FilteredExpression ) {
243- return ;
244- }
245- for (Expression child : expression .children ()) {
246- if (child instanceof FullTextFunction ftf ) {
247- failures .add (
248- fail (ftf , "[{}] {} is only supported in WHERE and STATS ... WHERE commands" , ftf .functionName (), ftf .functionType ())
249- );
250- return ;
251- }
252- checkFullTextFunctionsInAggs (child , failures );
253- }
240+ private static void checkFullTextFunctionsInAggs (Aggregate agg , Failures failures ) {
241+ agg .groupings ().forEach (exp -> {
242+ exp .forEachDown (e -> {
243+ if (e instanceof FullTextFunction ftf ) {
244+ failures .add (
245+ fail (ftf , "[{}] {} is only supported in WHERE and STATS ... WHERE commands" , ftf .functionName (), ftf .functionType ())
246+ );
247+ }
248+ });
249+ });
254250 }
255251
256252 /**
0 commit comments