diff --git a/server/src/main/java/org/elasticsearch/search/retriever/StandardRetrieverBuilder.java b/server/src/main/java/org/elasticsearch/search/retriever/StandardRetrieverBuilder.java index dd5d596e11728..4c965a12558f0 100644 --- a/server/src/main/java/org/elasticsearch/search/retriever/StandardRetrieverBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/retriever/StandardRetrieverBuilder.java @@ -131,8 +131,11 @@ public RetrieverBuilder rewrite(QueryRewriteContext ctx) throws IOException { var rewrittenFilters = rewritePreFilters(ctx); changed |= rewrittenFilters != preFilterQueryBuilders; - var queryBuilderRewrite = queryBuilder.rewrite(ctx); - changed |= queryBuilderRewrite != queryBuilder; + QueryBuilder queryBuilderRewrite = null; + if (queryBuilder != null) { + queryBuilderRewrite = queryBuilder.rewrite(ctx); + changed |= queryBuilderRewrite != queryBuilder; + } if (changed) { var rewritten = new StandardRetrieverBuilder(this);