MultiSearchRequest{Builder} throws NullPointerException in elasticsearch 1.3.2


(Veerapuram Varadhan) #1

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

public void performMultiSearchQuery () {
Client client = new TransportClient().addTransportAddress(new
InetSocketTransportAddress("localhost", 9300));
SearchRequestBuilder srb1 = client.prepareSearch()
.setQuery(QueryBuilders.queryString("sev:1")).setSize(Integer.MAX_VALUE);
SearchRequestBuilder srb2 = client.prepareSearch()
.setQuery(QueryBuilders.queryString("priority:50")).setSize(Integer.MAX_VALUE);

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,

V. Varadhan

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/badbc70d-6c2f-4f63-bb99-dec42addbfec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Veerapuram Varadhan) #2

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

public void performMultiSearchQuery () {
Client client = new TransportClient().addTransportAddress(new
InetSocketTransportAddress("localhost", 9300));
SearchRequestBuilder srb1 = client.prepareSearch()
.setQuery(QueryBuilders.queryString("sev:1")).setSize(Integer.MAX_VALUE);
SearchRequestBuilder srb2 = client.prepareSearch()

.setQuery(QueryBuilders.queryString("priority:50")).setSize(Integer.MAX_VALUE);

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,

V. Varadhan

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/b02c98f2-7df3-48e0-a0ba-b1d71967ae69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(David Pilato) #3

I think a NPE is always bad.
Could you check if this happens with 1.4.1 as well and if so, open an issue?

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 13 déc. 2014 à 18:32, Veerapuram Varadhan v.varadhan@gmail.com a écrit :

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

public void performMultiSearchQuery () {
Client client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
SearchRequestBuilder srb1 = client.prepareSearch()
.setQuery(QueryBuilders.queryString("sev:1")).setSize(Integer.MAX_VALUE);
SearchRequestBuilder srb2 = client.prepareSearch()
.setQuery(QueryBuilders.queryString("priority:50")).setSize(Integer.MAX_VALUE);

  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,

V. Varadhan

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/b02c98f2-7df3-48e0-a0ba-b1d71967ae69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/70B365A1-98D0-46EC-B3CE-391BB35E4912%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.


#4

it is almost 2017 and I get NPE :slight_smile:

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();

(David Pilato) #5

Would be better to open a new discussion.

Also remove > in your code snippet. Just use </> to format code.


(system) #6