[INNER HITS] Changed DisMaxQueryBuilder to extract inner hits from leaf queries.
Closes #23482
This commit is contained in:
parent
b01070a390
commit
78a48b102f
|
@ -33,6 +33,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
@ -206,4 +207,11 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder<DisMaxQueryBuilder>
|
|||
public String getWriteableName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void extractInnerHitBuilders(Map<String, InnerHitBuilder> innerHits) {
|
||||
for (QueryBuilder query : queries) {
|
||||
InnerHitBuilder.extractInnerHits(query, innerHits);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -183,6 +183,25 @@ public class InnerHitBuilderTests extends ESTestCase {
|
|||
assertThat(innerHitBuilders.get(leafInnerHits.getName()), notNullValue());
|
||||
}
|
||||
|
||||
public void testInlineLeafInnerHitsNestedQueryViaDisMaxQuery() {
|
||||
InnerHitBuilder leafInnerHits1 = randomInnerHits();
|
||||
NestedQueryBuilder nestedQueryBuilder = new NestedQueryBuilder("path", new MatchAllQueryBuilder(), ScoreMode.None)
|
||||
.innerHit(leafInnerHits1, false);
|
||||
|
||||
InnerHitBuilder leafInnerHits2 = randomInnerHits();
|
||||
HasChildQueryBuilder hasChildQueryBuilder = new HasChildQueryBuilder("type", new MatchAllQueryBuilder(), ScoreMode.None)
|
||||
.innerHit(leafInnerHits2, false);
|
||||
|
||||
DisMaxQueryBuilder disMaxQueryBuilder = new DisMaxQueryBuilder();
|
||||
disMaxQueryBuilder.add(nestedQueryBuilder);
|
||||
disMaxQueryBuilder.add(hasChildQueryBuilder);
|
||||
Map<String, InnerHitBuilder> innerHitBuilders = new HashMap<>();
|
||||
disMaxQueryBuilder.extractInnerHitBuilders(innerHitBuilders);
|
||||
assertThat(innerHitBuilders.size(), equalTo(2));
|
||||
assertThat(innerHitBuilders.get(leafInnerHits1.getName()), notNullValue());
|
||||
assertThat(innerHitBuilders.get(leafInnerHits2.getName()), notNullValue());
|
||||
}
|
||||
|
||||
public void testInlineLeafInnerHitsNestedQueryViaConstantScoreQuery() {
|
||||
InnerHitBuilder leafInnerHits = randomInnerHits();
|
||||
NestedQueryBuilder nestedQueryBuilder = new NestedQueryBuilder("path", new MatchAllQueryBuilder(), ScoreMode.None)
|
||||
|
|
Loading…
Reference in New Issue