diff --git a/core/src/main/java/org/elasticsearch/index/query/DisMaxQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/DisMaxQueryBuilder.java index 5061206eb1d..bd8e9031771 100644 --- a/core/src/main/java/org/elasticsearch/index/query/DisMaxQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/DisMaxQueryBuilder.java @@ -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 public String getWriteableName() { return NAME; } + + @Override + protected void extractInnerHitBuilders(Map innerHits) { + for (QueryBuilder query : queries) { + InnerHitBuilder.extractInnerHits(query, innerHits); + } + } } diff --git a/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java index 9774af189da..b46f3f3aa19 100644 --- a/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java @@ -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 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)