Multi level parent/child mapping and search fails, closes #1751.
This commit is contained in:
parent
1f6f81d840
commit
feaccee246
|
@ -105,10 +105,8 @@ public class QueryPhase implements SearchPhase {
|
|||
throw new QueryPhaseExecutionException(searchContext, "Failed to refresh id cache for child queries", e);
|
||||
}
|
||||
|
||||
// process scoped queries (from the last to the first, working with the parsing option here)
|
||||
for (int i = searchContext.scopePhases().size() - 1; i >= 0; i--) {
|
||||
ScopePhase scopePhase = searchContext.scopePhases().get(i);
|
||||
|
||||
// the first scope level is the most nested child
|
||||
for (ScopePhase scopePhase : searchContext.scopePhases()) {
|
||||
if (scopePhase instanceof ScopePhase.TopDocsPhase) {
|
||||
ScopePhase.TopDocsPhase topDocsPhase = (ScopePhase.TopDocsPhase) scopePhase;
|
||||
topDocsPhase.clear();
|
||||
|
|
|
@ -63,6 +63,32 @@ public class SimpleChildQuerySearchTests extends AbstractNodesTests {
|
|||
return client("node1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiLevelChild() throws Exception {
|
||||
client.admin().indices().prepareDelete().execute().actionGet();
|
||||
|
||||
client.admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
|
||||
client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
|
||||
client.admin().indices().preparePutMapping("test").setType("child").setSource(XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||
.startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
client.admin().indices().preparePutMapping("test").setType("grandchild").setSource(XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||
.startObject("_parent").field("type", "child").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
client.prepareIndex("test", "parent", "p1").setSource("p_field", "p_value1").execute().actionGet();
|
||||
client.prepareIndex("test", "child", "c1").setSource("c_field", "c_value1").setParent("p1").execute().actionGet();
|
||||
client.prepareIndex("test", "grandchild", "gc1").setSource("gc_field", "gc_value1").setParent("c1").setRouting("gc1").execute().actionGet();
|
||||
|
||||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
|
||||
SearchResponse searchResponse = client.prepareSearch("test")
|
||||
.setQuery(filteredQuery(matchAllQuery(), hasChildFilter("child", filteredQuery(termQuery("c_field", "c_value1"), hasChildFilter("grandchild", termQuery("gc_field", "gc_value1"))))))
|
||||
.execute().actionGet();
|
||||
assertThat("Failures " + Arrays.toString(searchResponse.shardFailures()), searchResponse.shardFailures().length, equalTo(0));
|
||||
assertThat(searchResponse.hits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleChildQuery() throws Exception {
|
||||
client.admin().indices().prepareDelete().execute().actionGet();
|
||||
|
|
Loading…
Reference in New Issue