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
This commit is contained in:
Jim Ferenczi 2019-01-30 08:46:14 +01:00 committed by GitHub
parent 5dcc805dc9
commit 2732bb5cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -129,7 +129,8 @@ final class ExpandSearchPhase extends SearchPhase {
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(),

View File

@ -252,6 +252,9 @@ public class ExpandSearchPhaseTests extends ESTestCase {
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()
@ -259,6 +262,7 @@ public class ExpandSearchPhaseTests extends ESTestCase {
new CollapseBuilder("someField")
.setInnerHits(new InnerHitBuilder().setName("foobarbaz").setVersion(version).setSeqNoAndPrimaryTerm(seqNoAndTerm))
)
.fetchSource(false)
.postFilter(QueryBuilders.existsQuery("foo")))
.preference("foobar")
.routing("baz");