Fixed `top_children` query failure with dfs_query* search types.
Fixed error with the top_children query when `DFS_QUERY_*` is used as search_type and wraps a query that gets rewritten (E.g wildcard query). Closes #2501
This commit is contained in:
parent
c17755d164
commit
08b026d060
|
@ -72,10 +72,12 @@ public class TopChildrenQuery extends Query implements ScopePhase.TopDocsPhase {
|
|||
|
||||
private Map<Object, ParentDoc[]> 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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue