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:
parent
5dcc805dc9
commit
2732bb5cf3
|
@ -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(),
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue