diff --git a/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java b/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java index 3c6d736fd8e..5af54eb1d09 100644 --- a/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java @@ -72,10 +72,12 @@ public class TopChildrenQuery extends Query implements ScopePhase.TopDocsPhase { private Map parentDocs; + // Actual value can get lost during query rewriting in dfs phase, but this isn't an issue now. private int numHits = 0; // Need to know if this query is properly used, otherwise the results are unexpected for example in the count api - private boolean properlyInvoked = false; + // Need to use boolean array instead of boolean primitive... b/c during query rewriting in dfs phase + private boolean[] properlyInvoked = new boolean[]{false}; // Note, the query is expected to already be filtered to only child type docs public TopChildrenQuery(Query query, String scope, String childType, String parentType, ScoreType scoreType, int factor, int incrementalFactor) { @@ -100,7 +102,7 @@ public class TopChildrenQuery extends Query implements ScopePhase.TopDocsPhase { @Override public void clear() { - properlyInvoked = true; + properlyInvoked[0] = true; parentDocs = null; numHits = 0; } @@ -208,7 +210,7 @@ public class TopChildrenQuery extends Query implements ScopePhase.TopDocsPhase { @Override public Weight createWeight(IndexSearcher searcher) throws IOException { - if (!properlyInvoked) { + if (!properlyInvoked[0]) { throw new ElasticSearchIllegalStateException("top_children query hasn't executed properly"); } diff --git a/src/test/java/org/elasticsearch/test/integration/search/child/SimpleChildQuerySearchTests.java b/src/test/java/org/elasticsearch/test/integration/search/child/SimpleChildQuerySearchTests.java index c62a3606aa6..97ef80c4cc9 100644 --- a/src/test/java/org/elasticsearch/test/integration/search/child/SimpleChildQuerySearchTests.java +++ b/src/test/java/org/elasticsearch/test/integration/search/child/SimpleChildQuerySearchTests.java @@ -695,6 +695,16 @@ public class SimpleChildQuerySearchTests extends AbstractNodesTests { .setQuery(boolQuery().mustNot(hasChildQuery("child", boolQuery().should(queryString("c_field:*"))).executionType(getExecutionMethod()))) .execute().actionGet(); assertThat("Failures " + Arrays.toString(searchResponse.shardFailures()), searchResponse.shardFailures().length, equalTo(0)); + + searchResponse = client.prepareSearch("test").setSearchType(SearchType.DFS_QUERY_THEN_FETCH) + .setQuery(boolQuery().mustNot(hasParentQuery("parent", boolQuery().should(queryString("p_field:*"))).executionType(getExecutionMethod()))) + .execute().actionGet(); + assertThat("Failures " + Arrays.toString(searchResponse.shardFailures()), searchResponse.shardFailures().length, equalTo(0)); + + searchResponse = client.prepareSearch("test").setSearchType(SearchType.DFS_QUERY_THEN_FETCH) + .setQuery(boolQuery().mustNot(topChildrenQuery("child", boolQuery().should(queryString("c_field:*"))))) + .execute().actionGet(); + assertThat("Failures " + Arrays.toString(searchResponse.shardFailures()), searchResponse.shardFailures().length, equalTo(0)); } @Test