Skip to content

Commit 2732bb5

Browse files
authored
Fix fetch source option in expand search phase (elastic#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 elastic#23829
1 parent 5dcc805 commit 2732bb5

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
@@ -252,13 +252,17 @@ void sendExecuteMultiSearch(MultiSearchRequest request, SearchTask task, ActionL
252252
assertTrue(request.requests().stream().allMatch((r) -> version == r.source().version()));
253253
assertTrue(request.requests().stream().allMatch((r) -> seqNoAndTerm == r.source().seqNoAndPrimaryTerm()));
254254
assertTrue(request.requests().stream().allMatch((r) -> postFilter.equals(r.source().postFilter())));
255+
assertTrue(request.requests().stream().allMatch((r) -> r.source().fetchSource().fetchSource() == false));
256+
assertTrue(request.requests().stream().allMatch((r) -> r.source().fetchSource().includes().length == 0));
257+
assertTrue(request.requests().stream().allMatch((r) -> r.source().fetchSource().excludes().length == 0));
255258
}
256259
};
257260
mockSearchPhaseContext.getRequest().source(new SearchSourceBuilder()
258261
.collapse(
259262
new CollapseBuilder("someField")
260263
.setInnerHits(new InnerHitBuilder().setName("foobarbaz").setVersion(version).setSeqNoAndPrimaryTerm(seqNoAndTerm))
261264
)
265+
.fetchSource(false)
262266
.postFilter(QueryBuilders.existsQuery("foo")))
263267
.preference("foobar")
264268
.routing("baz");

0 commit comments

Comments
 (0)