Skip to content

Commit

Permalink
Fixed AOBE when using top_children in a must not clause.
Browse files Browse the repository at this point in the history
Closes #2500
  • Loading branch information
martijnvg committed Dec 21, 2012
1 parent 370628d commit 3a599cf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
Expand Up @@ -282,6 +282,10 @@ private ParentScorer(Similarity similarity, ParentDoc[] docs) throws IOException

@Override
public int docID() {
if (index == -1) {
return -1;
}

if (index >= docs.length) {
return NO_MORE_DOCS;
}
Expand Down
Expand Up @@ -32,9 +32,11 @@
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;
Expand Down Expand Up @@ -657,6 +659,32 @@ public void testDfsSearchType() throws Exception {
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();
Expand Down Expand Up @@ -711,19 +739,19 @@ public void testHasChildAndHasParentFailWhenSomeSegmentsDontContainAnyParentOrCh
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();

Expand Down

0 comments on commit 3a599cf

Please sign in to comment.