# Regression in 0.20.0.Beta1-SNAPSHOT with Java API when using a single shard?

**URL:** https://discuss.elastic.co/t/regression-in-0-20-0-beta1-snapshot-with-java-api-when-using-a-single-shard/9175
**Category:** Elasticsearch
**Created:** [September 27, 2012, 8:21pm UTC](https://discuss.elastic.co/t/regression-in-0-20-0-beta1-snapshot-with-java-api-when-using-a-single-shard/9175 "2012-09-27T20:21:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![andreasch](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@andreasch](https://discuss.elastic.co/u/andreasch)
#### Post date: [September 27, 2012, 8:21pm UTC](https://discuss.elastic.co/t/regression-in-0-20-0-beta1-snapshot-with-java-api-when-using-a-single-shard/9175/1 "2012-09-27T20:21:00Z")

</div>

I have the following code that works with no errors on 0.19.9.0:

Client client = nodeBuilder().local(true).data(true).node().client();  
IndicesAdminClient indicesClient = client.admin().indices();

boolean exists = indicesClient.prepareExists("single-shard").execute()  
.actionGet().exists();

if (exists) {  
indicesClient.prepareDelete("single-shard").execute().actionGet();  
}

indicesClient  
.prepareCreate("single-shard")  
.setSettings(  
ImmutableSettings.settingsBuilder()  
.put("number\_of\_shards", 1)  
.put("number\_of\_replicas", 0)).execute()  
.actionGet();

XContentBuilder indexMapping = jsonBuilder().startObject()  
.startObject("orderType").startObject("\_parent")  
.field("type", "contactType").endObject().endObject()  
.endObject();

indicesClient.preparePutMapping("single-shard").setType("orderType")  
.setSource(indexMapping).execute().actionGet();

indexMapping = jsonBuilder().startObject().startObject("productType")  
.startObject("\_parent").field("type", "orderType").endObject()  
.endObject().endObject();

indicesClient.preparePutMapping("single-shard").setType("productType")  
.setSource(indexMapping).execute().actionGet();

XContentBuilder jsonBuilder = jsonBuilder().startObject()  
.field("fieldName", "fieldValue").endObject();

client.prepareIndex("single-shard", "contactType", "1")  
.setRefresh(true).setSource(jsonBuilder).execute().actionGet();

HasChildFilterBuilder hasChildFilterBuilder = hasChildFilter(  
"productType", matchAllQuery());

FilteredQueryBuilder filteredQuery = filteredQuery(matchAllQuery(),  
hasChildFilterBuilder);

client.prepareSearch("single-shard").setQuery(filteredQuery).execute()  
.actionGet();

However, on 0.20.0.Beta1-SNAPSHOT I get the following error:Exception in  
thread "main"  
org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to  
execute phase [query\_fetch], total failure; shardFailures  
{[1][single-shard][0]: QueryPhaseExecutionException[[single-shard][0]:  
query[ConstantScore(NotDeleted(child\_filter[productType/orderType](filtered(ConstantScore(NotDeleted(_:_)))-\>cache(\_type:productType))))],from[0],size[10]:  
Query Failed [Failed to execute main query]]; nested: NullPointerException;  
}  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:260)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onFailure(TransportSearchTypeAction.java:213)  
at  
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteFetch(SearchServiceTransportAction.java:243)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryAndFetchAction.java:75)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:205)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:192)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:178)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:662)

Also, the error goes away if I increase the number of shards used to more  
than 1.

--

---

<div class="post-metadata">

### Author: ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)
#### Post date: [September 28, 2012, 2:24pm UTC](https://discuss.elastic.co/t/regression-in-0-20-0-beta1-snapshot-with-java-api-when-using-a-single-shard/9175/2 "2012-09-28T14:24:54Z")

</div>

Hi Andreas,

This is a bug. I've opened an issue for it:

> <https://github.com/elastic/elasticsearch/issues/2297>

Martijn

On 27 September 2012 22:21, Andreas Christoforides  
[andreas.christoforides@gmail.com](mailto:andreas.christoforides@gmail.com) wrote:

> I have the following code that works with no errors on 0.19.9.0:
> 
> Client client = nodeBuilder().local(true).data(true).node().client();  
> IndicesAdminClient indicesClient = client.admin().indices();
> 
> boolean exists = indicesClient.prepareExists("single-shard").execute()  
> .actionGet().exists();
> 
> if (exists) {  
> indicesClient.prepareDelete("single-shard").execute().actionGet();  
> }
> 
> indicesClient  
> .prepareCreate("single-shard")  
> .setSettings(  
> ImmutableSettings.settingsBuilder()  
> .put("number\_of\_shards", 1)  
> .put("number\_of\_replicas", 0)).execute()  
> .actionGet();
> 
> XContentBuilder indexMapping = jsonBuilder().startObject()  
> .startObject("orderType").startObject("\_parent")  
> .field("type", "contactType").endObject().endObject()  
> .endObject();
> 
> indicesClient.preparePutMapping("single-shard").setType("orderType")  
> .setSource(indexMapping).execute().actionGet();
> 
> indexMapping = jsonBuilder().startObject().startObject("productType")  
> .startObject("\_parent").field("type", "orderType").endObject()  
> .endObject().endObject();
> 
> indicesClient.preparePutMapping("single-shard").setType("productType")  
> .setSource(indexMapping).execute().actionGet();
> 
> XContentBuilder jsonBuilder = jsonBuilder().startObject()  
> .field("fieldName", "fieldValue").endObject();
> 
> client.prepareIndex("single-shard", "contactType", "1")  
> .setRefresh(true).setSource(jsonBuilder).execute().actionGet();
> 
> HasChildFilterBuilder hasChildFilterBuilder = hasChildFilter(  
> "productType", matchAllQuery());
> 
> FilteredQueryBuilder filteredQuery = filteredQuery(matchAllQuery(),  
> hasChildFilterBuilder);
> 
> client.prepareSearch("single-shard").setQuery(filteredQuery).execute()  
> .actionGet();
> 
> However, on 0.20.0.Beta1-SNAPSHOT I get the following error:Exception in  
> thread "main" org.elasticsearch.action.search.SearchPhaseExecutionException:  
> Failed to execute phase [query\_fetch], total failure; shardFailures  
> {[1][single-shard][0]: QueryPhaseExecutionException[[single-shard][0]:  
> query[ConstantScore(NotDeleted(child\_filterproductType/orderType))],from[0],size[10]:  
> Query Failed [Failed to execute main query]]; nested: NullPointerException;  
> }  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:260)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onFailure(TransportSearchTypeAction.java:213)  
> at  
> org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteFetch(SearchServiceTransportAction.java:243)  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryAndFetchAction.java:75)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:205)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:192)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:178)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
> at java.lang.Thread.run(Thread.java:662)
> 
> Also, the error goes away if I increase the number of shards used to more  
> than 1.
> 
> --

--  
Met vriendelijke groet,

Martijn van Groningen

--

---

<div class="post-metadata">

### Author: ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)
#### Post date: [September 28, 2012, 3:14pm UTC](https://discuss.elastic.co/t/regression-in-0-20-0-beta1-snapshot-with-java-api-when-using-a-single-shard/9175/3 "2012-09-28T15:14:16Z")

</div>

Hi Andreas,

I pushed the bug fix. The code you attached works now on my machine.  
Can you also verify this?

Martijn

On 28 September 2012 16:24, Martijn v Groningen  
[martijn.v.groningen@gmail.com](mailto:martijn.v.groningen@gmail.com) wrote:

> Hi Andreas,
> 
> This is a bug. I've opened an issue for it:  
> [has\_child / has\_parent filters can throw NPE when either child or parent documents aren't indexed yet · Issue #2297 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2297)
> 
> Martijn
> 
> On 27 September 2012 22:21, Andreas Christoforides  
> [andreas.christoforides@gmail.com](mailto:andreas.christoforides@gmail.com) wrote:
> 
> > I have the following code that works with no errors on 0.19.9.0:
> > 
> > Client client = nodeBuilder().local(true).data(true).node().client();  
> > IndicesAdminClient indicesClient = client.admin().indices();
> > 
> > boolean exists = indicesClient.prepareExists("single-shard").execute()  
> > .actionGet().exists();
> > 
> > if (exists) {  
> > indicesClient.prepareDelete("single-shard").execute().actionGet();  
> > }
> > 
> > indicesClient  
> > .prepareCreate("single-shard")  
> > .setSettings(  
> > ImmutableSettings.settingsBuilder()  
> > .put("number\_of\_shards", 1)  
> > .put("number\_of\_replicas", 0)).execute()  
> > .actionGet();
> > 
> > XContentBuilder indexMapping = jsonBuilder().startObject()  
> > .startObject("orderType").startObject("\_parent")  
> > .field("type", "contactType").endObject().endObject()  
> > .endObject();
> > 
> > indicesClient.preparePutMapping("single-shard").setType("orderType")  
> > .setSource(indexMapping).execute().actionGet();
> > 
> > indexMapping = jsonBuilder().startObject().startObject("productType")  
> > .startObject("\_parent").field("type", "orderType").endObject()  
> > .endObject().endObject();
> > 
> > indicesClient.preparePutMapping("single-shard").setType("productType")  
> > .setSource(indexMapping).execute().actionGet();
> > 
> > XContentBuilder jsonBuilder = jsonBuilder().startObject()  
> > .field("fieldName", "fieldValue").endObject();
> > 
> > client.prepareIndex("single-shard", "contactType", "1")  
> > .setRefresh(true).setSource(jsonBuilder).execute().actionGet();
> > 
> > HasChildFilterBuilder hasChildFilterBuilder = hasChildFilter(  
> > "productType", matchAllQuery());
> > 
> > FilteredQueryBuilder filteredQuery = filteredQuery(matchAllQuery(),  
> > hasChildFilterBuilder);
> > 
> > client.prepareSearch("single-shard").setQuery(filteredQuery).execute()  
> > .actionGet();
> > 
> > However, on 0.20.0.Beta1-SNAPSHOT I get the following error:Exception in  
> > thread "main" org.elasticsearch.action.search.SearchPhaseExecutionException:  
> > Failed to execute phase [query\_fetch], total failure; shardFailures  
> > {[1][single-shard][0]: QueryPhaseExecutionException[[single-shard][0]:  
> > query[ConstantScore(NotDeleted(child\_filterproductType/orderType))],from[0],size[10]:  
> > Query Failed [Failed to execute main query]]; nested: NullPointerException;  
> > }  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:260)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onFailure(TransportSearchTypeAction.java:213)  
> > at  
> > org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteFetch(SearchServiceTransportAction.java:243)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryAndFetchAction.java:75)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:205)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:192)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:178)  
> > at  
> > java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
> > at  
> > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
> > at java.lang.Thread.run(Thread.java:662)
> > 
> > Also, the error goes away if I increase the number of shards used to more  
> > than 1.
> > 
> > --
> 
> --  
> Met vriendelijke groet,
> 
> Martijn van Groningen

--  
Met vriendelijke groet,

Martijn van Groningen

--

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 3:10am UTC](https://discuss.elastic.co/t/regression-in-0-20-0-beta1-snapshot-with-java-api-when-using-a-single-shard/9175/4 "2017-07-06T03:10:51Z")

</div>


