Fixed AOBE when using `top_children` in a must not clause.

Closes #2500
This commit is contained in:
Martijn van Groningen 2012-12-21 16:47:03 +01:00
parent 826a6ab02a
commit 694989141b
2 changed files with 43 additions and 11 deletions

View File

@ -284,6 +284,10 @@ public class TopChildrenQuery extends Query implements ScopePhase.TopDocsPhase {
@Override
public int docID() {
if (index == -1) {
return -1;
}
if (index >= docs.length) {
return NO_MORE_DOCS;
}

View File

@ -32,9 +32,11 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;
import static org.elasticsearch.index.query.FilterBuilders.hasChildFilter;
import static org.elasticsearch.index.query.FilterBuilders.hasParentFilter;
@ -695,6 +697,32 @@ public class SimpleChildQuerySearchTests extends AbstractNodesTests {
assertThat("Failures " + Arrays.toString(searchResponse.shardFailures()), searchResponse.shardFailures().length, equalTo(0));
}
@Test
public void testFixAOBEIfTopChildrenIswrappedInMusNotClause() throws Exception {
client.admin().indices().prepareDelete().execute().actionGet();
client.admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0)).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();
// index simple data
client.prepareIndex("test", "parent", "p1").setSource("p_field", "p_value1").execute().actionGet();
client.prepareIndex("test", "child", "c1").setSource("c_field", "red").setParent("p1").execute().actionGet();
client.prepareIndex("test", "child", "c2").setSource("c_field", "yellow").setParent("p1").execute().actionGet();
client.prepareIndex("test", "parent", "p2").setSource("p_field", "p_value2").execute().actionGet();
client.prepareIndex("test", "child", "c3").setSource("c_field", "blue").setParent("p2").execute().actionGet();
client.prepareIndex("test", "child", "c4").setSource("c_field", "red").setParent("p2").execute().actionGet();
client.admin().indices().prepareRefresh().execute().actionGet();
SearchResponse searchResponse = client.prepareSearch("test").setSearchType(SearchType.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
public void testTopChildrenReSearchBug() throws Exception {
client.admin().indices().prepareDelete().execute().actionGet();
@ -754,19 +782,19 @@ public class SimpleChildQuerySearchTests extends AbstractNodesTests {
client.admin().indices().prepareDelete().execute().actionGet();
client.admin().indices().prepareCreate("test").setSettings(
ImmutableSettings.settingsBuilder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0)
).execute().actionGet();
ImmutableSettings.settingsBuilder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0)
).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()
.startObject("type")
.startObject("_parent")
.field("type", "parent")
.endObject()
.endObject()
.endObject()
).execute().actionGet();