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

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.

--

Hi Andreas,

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

Martijn

On 27 September 2012 22:21, Andreas Christoforides
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

--

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 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

Martijn

On 27 September 2012 22:21, Andreas Christoforides
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

--