NullPointerException in MultiSearch API


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 :

public static void requestBuilder(ArrayList<String> formulae) {
		ArrayList<SearchRequestBuilder> srb = new ArrayList<SearchRequestBuilder>(formulae.size());	
		Client client = TransportClient.builder().build()
				.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("localhost",9300))); 
	int i = 0;
		MultiSearchRequestBuilder sr = client.prepareMultiSearch();
		for (String formula : formulae) {
			i += 1;

		MultiSearchResponse resp = sr.execute().actionGet(); 
			long nbHits = 0;
			for (MultiSearchResponse.Item item : resp.getResponses()){
				SearchResponse response = item.getResponse();
			//	nbHits += response.getHits().getTotalHits();

But when I use the following code, I can get get results from any field:

SearchResponse response = client.prepareSearch()
					for (SearchHit hit : response.getHits()) {
						String get = hit.getSource().get("text").toString();

How can I do the same with MultiSearch Api?

(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.