# Rest Client listener timeout after waiting for \[30000\] ms

**URL:** https://discuss.elastic.co/t/rest-client-listener-timeout-after-waiting-for-30000-ms/101326
**Category:** Elasticsearch
**Created:** [September 21, 2017, 12:15pm UTC](https://discuss.elastic.co/t/rest-client-listener-timeout-after-waiting-for-30000-ms/101326 "2017-09-21T12:15:09Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ajit](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@ajit](https://discuss.elastic.co/u/ajit)
#### Post date: [September 21, 2017, 12:15pm UTC](https://discuss.elastic.co/t/rest-client-listener-timeout-after-waiting-for-30000-ms/101326/1 "2017-09-21T12:15:09Z")

</div>

I am using RestClient bulk api to push excel data to elasticsearch but I am getting  
listener timeout after waiting for [30000] ms.  
my jar version are  
httpasyncclient-4.1.2.jar  
httpclient-4.5.2.jar  
httpcore-4.4.5.jar  
httpcore-nio-4.4.5.jar  
rest-5.3.0.jar

Please provide me solution for listener timeout after waiting for [30000] ms

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 21, 2017, 3:41pm UTC](https://discuss.elastic.co/t/rest-client-listener-timeout-after-waiting-for-30000-ms/101326/2 "2017-09-21T15:41:12Z")

</div>

No idea. I don't know what you are exactly doing...

---

<div class="post-metadata">

### Author: ![ajit](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@ajit](https://discuss.elastic.co/u/ajit)
#### Post date: [September 22, 2017, 5:15am UTC](https://discuss.elastic.co/t/rest-client-listener-timeout-after-waiting-for-30000-ms/101326/3 "2017-09-22T05:15:56Z")

</div>

I am reading excel file and pushing data to elasticsearch using RestClient bulk API. It is working fine with localhost  
but giving listener timeout exception for remote machine i.e. remote elasticsearch. Sometime data gets push into remote elasticsearch but sometime getting this exception. Please provide solution.

Below is my code.

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");  
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));  
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200, "http")).build();

JSONObject obj = new JSONObject();

FileInputStream file = new FileInputStream(new File("C:\Users\cajitb\Desktop\TempFiles\op\TestExcel.xlsx"));  
Workbook workbook = new Workbook(file);  
Worksheet worksheet = workbook.getWorksheets().get(0);  
Cells cells = worksheet.getCells();

```
	Range range = cells.getMaxDisplayRange();
	int totalColumns = range.getColumnCount();
	int totalRows = range.getRowCount();
	RowCollection rows = cells.getRows();
    
	int maxColumn = cells.getMaxDataColumn();
	int maxRows = cells.getMaxDataRow();

	SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	Date d1 = new Date();
	
	
	List<Object> colList = new ArrayList<Object>();
	String actionMetaData = String.format("{ \"index\" : { \"_index\" : \"%s\", \"_type\" : \"%s\" } }%n", "jsonindex", "jsonindextype");
	for(int i = 0; i<=0 ; i++)
	{
		for (int j = 0; j < totalColumns; j++) 
	    {
			colList.add(cells.get(i, j).getValue());
	    }
	}
	List<String> bulkData = new ArrayList<String>();
	for (int i = 1; i < rows.getCount(); i++) 
	{
	    for (int j = 0; j < totalColumns; j++) 
	    {
	    	String key = (String)colList.get(j); 
	    	if(null==key || "".equals(key))
	    		key = "Column"+j;
	    	obj.put(key, cells.get(i, j).getValue());
	       
	    }
	     Date d = new Date();
	    obj.put("Action_Date", dateFormat.format(d));
	    
	    String jsonString = obj.toJSONString();
	    bulkData.add(jsonString);
		obj.clear();
	}
	
	Date d2 = new Date();
	StringBuilder bulkRequestBody = new StringBuilder();
	for (String bulkItem : bulkData) {
	    bulkRequestBody.append(actionMetaData);
	    bulkRequestBody.append(bulkItem);
	    bulkRequestBody.append("\n");
	}
    HttpEntity entity = new NStringEntity(bulkRequestBody.toString(), ContentType.APPLICATION_JSON);
   Response indexResponse = restClient.performRequest(
			"POST",
			"/jsonindex/jsonindextype/_bulk",
			Collections.<String, String>emptyMap(),
			entity);
			//System.out.println(EntityUtils.toString(indexResponse.getEntity()));
	if(indexResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
	{
		System.out.println("Index Successfully Created");
	}
```

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 22, 2017, 5:54am UTC](https://discuss.elastic.co/t/rest-client-listener-timeout-after-waiting-for-30000-ms/101326/4 "2017-09-22T05:54:13Z")

</div>

Try with less requests within a bulk. But I think I already told you that.

---

<div class="post-metadata">

### Author: ![ajit](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@ajit](https://discuss.elastic.co/u/ajit)
#### Post date: [September 25, 2017, 5:39am UTC](https://discuss.elastic.co/t/rest-client-listener-timeout-after-waiting-for-30000-ms/101326/5 "2017-09-25T05:39:16Z")

</div>

I am now pushing half of the data in one request and half of the data in second request. Though I am getting the below exception : listener timeout after waiting for [30000] ms  
Below is my code :

```auto
try {
		
JSONObject obj = new JSONObject();
		
FileInputStream file = new FileInputStream(new File("C:\\Users\\cajitb\\Desktop\\TempFiles\\op\\TestExcel01.xlsx"));
Workbook workbook = new Workbook(file);
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
		
		Range range = cells.getMaxDisplayRange();
		int totalColumns = range.getColumnCount();
		int totalRows = range.getRowCount();
		RowCollection rows = cells.getRows();
		int maxColumn = cells.getMaxDataColumn();
		int maxRows = cells.getMaxDataRow();
	
		SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Date d1 = new Date();
		System.out.println("Start Time:"+format.format(d1));
		
		List<Object> colList = new ArrayList<Object>();
		String actionMetaData = String.format("{ \"index\" : { \"_index\" : \"%s\", \"_type\" : \"%s\" } }%n", "jsonindex", "jsonindextype");
		for(int i = 0; i<=0 ; i++)
		{
			for (int j = 0; j < totalColumns; j++) 
		    {
				colList.add(cells.get(i, j).getValue());
		    }
		}
		List<String> bulkData = new ArrayList<String>();
		for (int i = 1; i < rows.getCount(); i++) 
		{
		    for (int j = 0; j < totalColumns; j++) 
		    {
		    	String key = (String)colList.get(j); 
		    	if(null==key || "".equals(key))
		    		key = "Column"+j;
		    	obj.put(key, cells.get(i, j).getValue());
		    }
	  
		    Date d = new Date();
		    obj.put("Action_Date", dateFormat.format(d));
		    
		    String jsonString = obj.toJSONString();
		    bulkData.add(jsonString);
			obj.clear();
		}
		StringBuilder bulkRequestBody = new StringBuilder();
		
		int halfListIndex = 0;
		if(bulkData.size()>30000)
		{
			halfListIndex = bulkData.size()/2;
			
			for(int i=0;i<bulkData.size()/2;i++)
			{
				bulkRequestBody.append(actionMetaData);
			    bulkRequestBody.append(bulkData.get(i));
			    bulkRequestBody.append("\n");
			}
			String jsonString = bulkRequestBody.toString();
			bulkRequestBody.setLength(0);
			HttpEntity entity = new NStringEntity(jsonString, ContentType.APPLICATION_JSON);
			Response indexResponse = restClient.performRequest(
					"PUT",
					"/jsonindex/jsonindextype/_bulk",
					Collections.<String, String>emptyMap(),
					entity);
					
			if(indexResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
			{
				System.out.println("Index Successfully Created");
			}
		}
		
		if(bulkData.size()>30000)
		{
			for(int i = halfListIndex; i<bulkData.size();i++)
			{
				bulkRequestBody.append(actionMetaData);
				bulkRequestBody.append(bulkData.get(i));
				bulkRequestBody.append("\n");
			}
			String jsonString = bulkRequestBody.toString();
			bulkRequestBody.setLength(0);
			HttpEntity entity = new NStringEntity(jsonString, ContentType.APPLICATION_JSON);
			Response indexResponse = restClient.performRequest(
					"PUT",
					"/jsonindex/jsonindextype/_bulk",
					Collections.<String, String>emptyMap(),
					entity);
					//System.out.println(EntityUtils.toString(indexResponse.getEntity()));
			if(indexResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
			{
				System.out.println("Index Successfully Created");
			}
		}
		
		if(bulkData.size()<30000)
		{
			for (String bulkItem : bulkData) {
			    bulkRequestBody.append(actionMetaData);
			    bulkRequestBody.append(bulkItem);
			    bulkRequestBody.append("\n");
			}
			String jsonString = bulkRequestBody.toString();
			bulkRequestBody.setLength(0);
			HttpEntity entity = new NStringEntity(jsonString, ContentType.APPLICATION_JSON);
			Response indexResponse = restClient.performRequest(
					"PUT",
					"/jsonindex/jsonindextype/_bulk",
					Collections.<String, String>emptyMap(),
					entity);
					//System.out.println(EntityUtils.toString(indexResponse.getEntity()));
			if(indexResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
			{
				System.out.println("Index Successfully Created");
			}
			
		}
	 }catch(Exception e)
	{
		 System.out.println("Exception Occure");
		 e.printStackTrace();
	} 

```

I have mentioned my jar versions used. Sometime I am not getting exception like this. Sometime it is giving exception. Please provide me solution. As per your solution I have divided my data to push into elk. Please provide solution.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 25, 2017, 6:35am UTC](https://discuss.elastic.co/t/rest-client-listener-timeout-after-waiting-for-30000-ms/101326/6 "2017-09-25T06:35:39Z")

</div>

Try with bulk with size of 1000 docs instead?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 23, 2017, 6:35am UTC](https://discuss.elastic.co/t/rest-client-listener-timeout-after-waiting-for-30000-ms/101326/7 "2017-10-23T06:35:42Z")

</div>

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