# RestClient always gives “I/O reactor status: STOPPED”

**URL:** <https://discuss.elastic.co/t/restclient-always-gives-i-o-reactor-status-stopped/201860>\
**Category:** Elasticsearch\
**Created:** [October 1, 2019, 8:06pm UTC](https://discuss.elastic.co/t/restclient-always-gives-i-o-reactor-status-stopped/201860 "2019-10-01T20:06:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![garry12](https://avatars.discourse-cdn.com/v4/letter/g/ac8455/32.png) [@garry12](https://discuss.elastic.co/u/garry12)\
**Post date:** [October 1, 2019, 8:06pm UTC](https://discuss.elastic.co/t/restclient-always-gives-i-o-reactor-status-stopped/201860/1 "2019-10-01T20:06:24Z")

</div>

I followed this thread but not able to resolve this issue I have a rest high level client and Elasticsearch 7.2 I am trying to bulk insert and keep getting this error -"java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED". Could anyone please help in getting me out of this?

---

<div class="post-metadata">

**Author:** ![garry12](https://avatars.discourse-cdn.com/v4/letter/g/ac8455/32.png) [@garry12](https://discuss.elastic.co/u/garry12)\
**Post date:** [October 1, 2019, 8:08pm UTC](https://discuss.elastic.co/t/restclient-always-gives-i-o-reactor-status-stopped/201860/2 "2019-10-01T20:08:02Z")

</div>

Here I am pasting the code snippet of my actual code ...

public class ElasticSearchLoader  
extends BaseLoader  
{

private RestHighLevelClient client;  
private BulkProcessor bulkProcessor;

private HashMap\<String, ElasticFieldMapper\> fieldMappers = new HashMap\<String, ElasticFieldMapper\>();

@Override  
protected void performBegin() throws InitializeException  
{  
super.performBegin();

```
client = ElasticSearchHelper
    .makeConnection(clusterName.stringValue(), server.stringValue(), port.intValue());

BulkProcessor.Listener listener = new BulkProcessor.Listener() { 
   
    @Override
    public void afterBulk(long executionId, BulkRequest request,
            BulkResponse response) {
    	for (BulkItemResponse resp : response.getItems()) {
          if (resp.isFailed()) {
            System.out.println(resp.getFailureMessage());
            getResults().reportProblem(
                "Elastic Search Load Error",
                Severity.Error,
                resp.getFailureMessage(),
                null);

          }
        }
    }

    @Override
    public void afterBulk(long executionId, BulkRequest request,
            Throwable failure) {
    	  context.log().warn("Error loading bulk elastic search requests", failure);
    }

@Override
public void beforeBulk(long executionId, BulkRequest request) {
  context.log().info("Creating bulk processor.");
  context.log().info("Number of actions: " + request.numberOfActions());
}
};

 bulkProcessor = BulkProcessor.builder(
        (request, bulkListener) ->
            client.bulkAsync(request, RequestOptions.DEFAULT, bulkListener),
        listener).build();

BulkProcessor.Builder builder = BulkProcessor.builder(
        (request, bulkListener) ->
            client.bulkAsync(request, RequestOptions.DEFAULT, bulkListener),
        listener);

builder.setBulkActions(bulkActions.intValue()); 
builder.setBulkSize(new ByteSizeValue(bulkSize.intValue(), ByteSizeUnit.MB));
builder.setFlushInterval(TimeValue.timeValueSeconds(flushSeconds.intValue()));
builder.setConcurrentRequests(concurrentRequests.intValue()).build();
builder.setBackoffPolicy(
        BackoffPolicy.exponentialBackoff(TimeValue.timeValueMillis(100), 3));

setFieldMappers();

```

// if (!indexExists()) {  
// setESFieldMapping();  
// }  
context.log().info(  
"Loading elastic search; server: "  
+ server.stringValue()  
+ ", cluster: "  
+ clusterName.stringValue()  
+ ", index: "  
+ docIndex.stringValue()  
+ ", type: "  
+ docType.stringValue());

}

@Override  
public void performLoad(Record item) throws InvalidRecordException, ETLSystemException  
{  
try {  
XContentBuilder builder = jsonBuilder().startObject();  
for (Parameter field : fields.getParameters()) {  
String name = field.getNamedValue("name").stringValue();

```
   // System.out.println("I am the E "+ name);
    ElasticFieldMapper e = fieldMappers.get(name);

   
    
    
    Object value = field.getValueExpression().value(item);
  // System.out.println();
    if (e.getType() != null) {
      value = TypeHelper.cast(value, e.getType());
  }
    builder.field(name, value);
  }
  builder.endObject();

  bulkProcessor.add(new IndexRequest(docIndex.stringValue(item).toLowerCase()).id(docId.stringValue(item)).source(builder));
  
}
catch (IOException ex) {
  throw new InvalidRecordException("Unable to load record", ex);
}

```

}

@Override  
public void performComplete() throws IOException, CompleteException  
{  
bulkProcessor.flush();

```
try {
    bulkProcessor.awaitClose(waitCloseMinutes.intValue(), TimeUnit.MINUTES);
  }
  catch (InterruptedException ex) {
    throw new CompleteException("Unable to close the bulk processor", ex);
  }
  finally {
    client.close();
  }

super.performComplete();

```

}

---

<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 29, 2019, 8:08pm UTC](https://discuss.elastic.co/t/restclient-always-gives-i-o-reactor-status-stopped/201860/3 "2019-10-29T20:08:06Z")

</div>

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