Skip to content

Commit

Permalink
Fix fetch source option in expand search phase (#37908)
Browse files Browse the repository at this point in the history
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
jimczi authored Jan 30, 2019
1 parent 5dcc805 commit 2732bb5
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -129,7 +129,8 @@ private SearchSourceBuilder buildExpandSearchSourceBuilder(InnerHitBuilder optio
options.getSorts().forEach(groupSource::sort);
}
if (options.getFetchSourceContext() != null) {
if (options.getFetchSourceContext().includes() == null && options.getFetchSourceContext().excludes() == null) {
if (options.getFetchSourceContext().includes().length == 0 &&
options.getFetchSourceContext().excludes().length == 0) {
groupSource.fetchSource(options.getFetchSourceContext().fetchSource());
} else {
groupSource.fetchSource(options.getFetchSourceContext().includes(),
Original file line number Diff line number Diff line change
@@ -252,13 +252,17 @@ void sendExecuteMultiSearch(MultiSearchRequest request, SearchTask task, ActionL
assertTrue(request.requests().stream().allMatch((r) -> version == r.source().version()));
assertTrue(request.requests().stream().allMatch((r) -> seqNoAndTerm == r.source().seqNoAndPrimaryTerm()));
assertTrue(request.requests().stream().allMatch((r) -> postFilter.equals(r.source().postFilter())));
assertTrue(request.requests().stream().allMatch((r) -> r.source().fetchSource().fetchSource() == false));
assertTrue(request.requests().stream().allMatch((r) -> r.source().fetchSource().includes().length == 0));
assertTrue(request.requests().stream().allMatch((r) -> r.source().fetchSource().excludes().length == 0));
}
};
mockSearchPhaseContext.getRequest().source(new SearchSourceBuilder()
.collapse(
new CollapseBuilder("someField")
.setInnerHits(new InnerHitBuilder().setName("foobarbaz").setVersion(version).setSeqNoAndPrimaryTerm(seqNoAndTerm))
)
.fetchSource(false)
.postFilter(QueryBuilders.existsQuery("foo")))
.preference("foobar")
.routing("baz");

0 comments on commit 2732bb5

Please sign in to comment.