If this is already answered, please point me to the thread. TIA for that.
Now, the problem:
I am having the following code to test MultiSearchRequest{Buuilder} and it
always throws me NullPointerException (even if I just use matchAllQuery()
in the SearchRequests added to it).
MultiSearchResponse sr = client.prepareMultiSearch()
.add(srb1.request())
.add(srb2.request())
.execute().actionGet();
// You will get all individual responses from
MultiSearchResponse#getResponses()
long nbHits = 0;
for (MultiSearchResponse.Item item : sr.getResponses()) {
SearchResponse response = item.getResponse();
nbHits += response.getHits().getTotalHits();
}
logger.info("Total Number of Hits: " + nbHits);
client.close();
}
And the exception it throws is:
Exception in thread "main"
org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:
Failed execution
at
org.elasticsearch.action.support.AdapterActionFuture.rethrowExecutionException(AdapterActionFuture.java:90)
at
org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:50)
at esclient.ESClient.buildQuery(ESClient.java:119)
at esclient.ESClient.main(ESClient.java:321)
Caused by: java.lang.NullPointerException
at
org.elasticsearch.action.search.SearchRequest.writeTo(SearchRequest.java:541)
at
org.elasticsearch.action.search.MultiSearchRequest.writeTo(MultiSearchRequest.java:271)
at
org.elasticsearch.transport.netty.NettyTransport.sendRequest(NettyTransport.java:601)
at
org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:206)
at
org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:68)
at
org.elasticsearch.client.transport.support.InternalTransportClient$2.doWithNode(InternalTransportClient.java:108)
at
org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:219)
at
org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:105)
at
org.elasticsearch.client.support.AbstractClient.multiSearch(AbstractClient.java:360)
at
org.elasticsearch.client.transport.TransportClient.multiSearch(TransportClient.java:441)
at
org.elasticsearch.action.search.MultiSearchRequestBuilder.doExecute(MultiSearchRequestBuilder.java:78)
at
org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91)
at
org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)
I have searched my best and you might notice that the above code is the
sample snippet from ES doc page. Please help me in figuring out what the
issue is.
P.S:- Individually both those SearchRequestBuilders are working fine.
Best,
That was so stupid of me forgetting to set the index and type params.!!
Looking at the SearchRequest.java:541 struck a big hammer on my head.!
Issue solved. Sorry for the false alarm.
Thanks,
V. Varadhan
On Saturday, December 13, 2014 10:35:18 PM UTC+5:30, Veerapuram Varadhan
wrote:
Hi,
If this is already answered, please point me to the thread. TIA for that.
Now, the problem:
I am having the following code to test MultiSearchRequest{Buuilder} and it
always throws me NullPointerException (even if I just use matchAllQuery()
in the SearchRequests added to it).
MultiSearchResponse sr = client.prepareMultiSearch()
.add(srb1.request())
.add(srb2.request())
.execute().actionGet();
// You will get all individual responses from
MultiSearchResponse#getResponses()
long nbHits = 0;
for (MultiSearchResponse.Item item : sr.getResponses()) {
SearchResponse response = item.getResponse();
nbHits += response.getHits().getTotalHits();
}
logger.info("Total Number of Hits: " + nbHits);
client.close();
}
And the exception it throws is:
Exception in thread "main"
org.elasticsearch.common.util.concurrent.UncategorizedExecutionException:
Failed execution
at
org.elasticsearch.action.support.AdapterActionFuture.rethrowExecutionException(AdapterActionFuture.java:90)
at
org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:50)
at esclient.ESClient.buildQuery(ESClient.java:119)
at esclient.ESClient.main(ESClient.java:321)
Caused by: java.lang.NullPointerException
at
org.elasticsearch.action.search.SearchRequest.writeTo(SearchRequest.java:541)
at
org.elasticsearch.action.search.MultiSearchRequest.writeTo(MultiSearchRequest.java:271)
at
org.elasticsearch.transport.netty.NettyTransport.sendRequest(NettyTransport.java:601)
at
org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:206)
at
org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:68)
at
org.elasticsearch.client.transport.support.InternalTransportClient$2.doWithNode(InternalTransportClient.java:108)
at
org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:219)
at
org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:105)
at
org.elasticsearch.client.support.AbstractClient.multiSearch(AbstractClient.java:360)
at
org.elasticsearch.client.transport.TransportClient.multiSearch(TransportClient.java:441)
at
org.elasticsearch.action.search.MultiSearchRequestBuilder.doExecute(MultiSearchRequestBuilder.java:78)
at
org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91)
at
org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)
I have searched my best and you might notice that the above code is the
sample snippet from ES doc page. Please help me in figuring out what the
issue is.
P.S:- Individually both those SearchRequestBuilders are working fine.
Best,
That was so stupid of me forgetting to set the index and type params.!! Looking at the SearchRequest.java:541 struck a big hammer on my head.!
Issue solved. Sorry for the false alarm.
Thanks,
V. Varadhan
On Saturday, December 13, 2014 10:35:18 PM UTC+5:30, Veerapuram Varadhan wrote:
Hi,
If this is already answered, please point me to the thread. TIA for that.
Now, the problem:
I am having the following code to test MultiSearchRequest{Buuilder} and it always throws me NullPointerException (even if I just use matchAllQuery() in the SearchRequests added to it).
MultiSearchResponse sr = client.prepareMultiSearch()
.add(srb1.request())
.add(srb2.request())
.execute().actionGet();
// You will get all individual responses from MultiSearchResponse#getResponses()
long nbHits = 0;
for (MultiSearchResponse.Item item : sr.getResponses()) {
SearchResponse response = item.getResponse();
nbHits += response.getHits().getTotalHits();
}
logger.info("Total Number of Hits: " + nbHits);
client.close();
}
And the exception it throws is:
Exception in thread "main" org.elasticsearch.common.util.concurrent.UncategorizedExecutionException: Failed execution
at org.elasticsearch.action.support.AdapterActionFuture.rethrowExecutionException(AdapterActionFuture.java:90)
at org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:50)
at esclient.ESClient.buildQuery(ESClient.java:119)
at esclient.ESClient.main(ESClient.java:321)
Caused by: java.lang.NullPointerException
at org.elasticsearch.action.search.SearchRequest.writeTo(SearchRequest.java:541)
at org.elasticsearch.action.search.MultiSearchRequest.writeTo(MultiSearchRequest.java:271)
at org.elasticsearch.transport.netty.NettyTransport.sendRequest(NettyTransport.java:601)
at org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:206)
at org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:68)
at org.elasticsearch.client.transport.support.InternalTransportClient$2.doWithNode(InternalTransportClient.java:108)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:219)
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:105)
at org.elasticsearch.client.support.AbstractClient.multiSearch(AbstractClient.java:360)
at org.elasticsearch.client.transport.TransportClient.multiSearch(TransportClient.java:441)
at org.elasticsearch.action.search.MultiSearchRequestBuilder.doExecute(MultiSearchRequestBuilder.java:78)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)
I have searched my best and you might notice that the above code is the sample snippet from ES doc page. Please help me in figuring out what the issue is.
P.S:- Individually both those SearchRequestBuilders are working fine.
Best,
I get NPE when I want to get nbHits, and I cannot get the value of any other field. But, when I disable this line, I get responses without error.
nbHits += response.getHits().getTotalHits();`
there is my whole code :
> int i = 0;
> ArrayList<SearchRequestBuilder> srb = new ArrayList<SearchRequestBuilder>(formulae.size());
> Client client = TransportClient.builder().build()
> .addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("localhost",9300)));
>
> MultiSearchRequestBuilder sr = client.prepareMultiSearch();
> for (String formula : formulae) {
> srb.add(client.prepareSearch(index).setSource(formula));
> sr.add(srb.get(i));
> i += 1;
> }
> MultiSearchResponse resp = sr.execute().actionGet();
>
>
> long nbHits = 0;
> for (MultiSearchResponse.Item item : resp.getResponses()){
> SearchResponse response = item.getResponse();
>
> nbHits += response.getHits().getTotalHits();
>
>
> System.out.println(response);
>
> }
> client.close();
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.