[INNER HITS] Changed DisMaxQueryBuilder to extract inner hits from leaf queries.

Closes #23482
This commit is contained in:
Martijn van Groningen 2017-03-06 14:37:38 +01:00
parent b01070a390
commit 78a48b102f
No known key found for this signature in database
GPG Key ID: AB236F4FCF2AF12A
2 changed files with 27 additions and 0 deletions

View File

@ -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);
}
}
}

View File

@ -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)