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