Skip to content

Commit 2a82ff5

Browse files
committed
Fix fetch source option in expand search phase (#37908)
This change fixes the copy of the fetch source option into the expand search request that is used to retrieve the documents of each collapsed group. Closes #23829
1 parent e28baac commit 2a82ff5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

server/src/main/java/org/elasticsearch/action/search/ExpandSearchPhase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ private SearchSourceBuilder buildExpandSearchSourceBuilder(InnerHitBuilder optio
129129
options.getSorts().forEach(groupSource::sort);
130130
}
131131
if (options.getFetchSourceContext() != null) {
132-
if (options.getFetchSourceContext().includes() == null && options.getFetchSourceContext().excludes() == null) {
132+
if (options.getFetchSourceContext().includes().length == 0 &&
133+
options.getFetchSourceContext().excludes().length == 0) {
133134
groupSource.fetchSource(options.getFetchSourceContext().fetchSource());
134135
} else {
135136
groupSource.fetchSource(options.getFetchSourceContext().includes(),

server/src/test/java/org/elasticsearch/action/search/ExpandSearchPhaseTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,17 @@ void sendExecuteMultiSearch(MultiSearchRequest request, SearchTask task, ActionL
248248
assertTrue(request.requests().stream().allMatch((r) -> version == r.source().version()));
249249
assertTrue(request.requests().stream().allMatch((r) -> seqNoAndTerm == r.source().seqNoAndPrimaryTerm()));
250250
assertTrue(request.requests().stream().allMatch((r) -> postFilter.equals(r.source().postFilter())));
251+
assertTrue(request.requests().stream().allMatch((r) -> r.source().fetchSource().fetchSource() == false));
252+
assertTrue(request.requests().stream().allMatch((r) -> r.source().fetchSource().includes().length == 0));
253+
assertTrue(request.requests().stream().allMatch((r) -> r.source().fetchSource().excludes().length == 0));
251254
}
252255
};
253256
mockSearchPhaseContext.getRequest().source(new SearchSourceBuilder()
254257
.collapse(
255258
new CollapseBuilder("someField")
256259
.setInnerHits(new InnerHitBuilder().setName("foobarbaz").setVersion(version).setSeqNoAndPrimaryTerm(seqNoAndTerm))
257260
)
261+
.fetchSource(false)
258262
.postFilter(QueryBuilders.existsQuery("foo")))
259263
.preference("foobar")
260264
.routing("baz");

0 commit comments

Comments
 (0)