# RestHighLevelClient: Force merge async and SocketTimeoutException

**URL:** <https://discuss.elastic.co/t/resthighlevelclient-force-merge-async-and-sockettimeoutexception/196133>\
**Category:** Elasticsearch\
**Created:** [August 21, 2019, 2:32pm UTC](https://discuss.elastic.co/t/resthighlevelclient-force-merge-async-and-sockettimeoutexception/196133 "2019-08-21T14:32:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [August 21, 2019, 2:32pm UTC](https://discuss.elastic.co/t/resthighlevelclient-force-merge-async-and-sockettimeoutexception/196133/1 "2019-08-21T14:32:48Z")

</div>

Hi,

I have the following problem after trying to upgrade my Java code to the RestHighLevelClient.

At the end of a big process of reindexation, there is an old piece of code that run a Force Merge.  
I have replaced with a call to forcemergeAsync(), and expect that the process will be notified when the merge is finished (takes ~20 minutes for very big indices), but the query seems to wait and the socket die with a SocketTimeoutException (That's normal).

My questions are:  
What is the good way to run this kind of long query ?  
Is there a problem in Java client or is my code bad ? I can believe it 🙂  
Do I have to run it in a task and watch the task (seems to be the good solution) ?

Here is the code:

```
				logger.info("### Force merge...");

			final CountDownLatch countDownLatch = new CountDownLatch(1);

			ActionListener<ForceMergeResponse> listener = new ActionListener<ForceMergeResponse>() {

				@Override
				public void onResponse(ForceMergeResponse response) {
					isOk.set(true);
			        countDownLatch.countDown();
				}

				@Override
				public void onFailure(Exception e) {
					isOk.set(false);
					logger.severe(ExceptionUtils.getFullStackTrace(e));
					countDownLatch.countDown();
				}
			};

			client.indices().forcemergeAsync(
					new ForceMergeRequest(indexName).maxNumSegments(forceMergeMaxNumSegments) /*.createTask(id, type, action, parentTaskId, headers)*/, 
					RequestOptions.DEFAULT, 
					listener);

			// wait max 1h for async request to perform the merge request
			boolean finishNormaly = countDownLatch.await(1, TimeUnit.HOURS);
			if(!finishNormaly) {
				throw new InterruptedException();
			}

```

After 30s, the onFailure is called, and that's bad for me ☹

Thank you,  
Xavier

---

<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:** [September 18, 2019, 2:32pm UTC](https://discuss.elastic.co/t/resthighlevelclient-force-merge-async-and-sockettimeoutexception/196133/2 "2019-09-18T14:32:52Z")

</div>

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