diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/queries/SemanticMatchQueryRewriteInterceptor.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/queries/SemanticMatchQueryRewriteInterceptor.java index 2659931ae5d4a..d1d5dab761f2a 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/queries/SemanticMatchQueryRewriteInterceptor.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/queries/SemanticMatchQueryRewriteInterceptor.java @@ -57,7 +57,9 @@ public QueryBuilder rewrite(QueryRewriteContext context, QueryBuilder queryBuild } } - if (inferenceIndices.isEmpty() == false && nonInferenceIndices.isEmpty() == false) { + if (inferenceIndices.isEmpty()) { + return rewritten; + } else if (nonInferenceIndices.isEmpty() == false) { BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder(); for (String inferenceIndexName : inferenceIndices) { // Add a separate clause for each semantic query, because they may be using different inference endpoints @@ -69,10 +71,11 @@ public QueryBuilder rewrite(QueryRewriteContext context, QueryBuilder queryBuild createMatchSubQuery(nonInferenceIndices, matchQueryBuilder.fieldName(), matchQueryBuilder.value()) ); rewritten = boolQueryBuilder; - } else if (inferenceIndices.isEmpty() == false) { + } else { rewritten = new SemanticQueryBuilder(matchQueryBuilder.fieldName(), (String) matchQueryBuilder.value(), true); } } + return rewritten; }