# Delete async on response of update async does not work

**URL:** <https://discuss.elastic.co/t/delete-async-on-response-of-update-async-does-not-work/287724>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [October 26, 2021, 6:52pm UTC](https://discuss.elastic.co/t/delete-async-on-response-of-update-async-does-not-work/287724 "2021-10-26T18:52:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giovanni\_Di\_Lembo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/giovanni_di_lembo/32/45714_2.png) [@Giovanni\_Di\_Lembo](https://discuss.elastic.co/u/Giovanni_Di_Lembo)\
**Post date:** [October 26, 2021, 6:52pm UTC](https://discuss.elastic.co/t/delete-async-on-response-of-update-async-does-not-work/287724/1 "2021-10-26T18:52:58Z")

</div>

Hi all and sorry for my poor english  
I'm calling an updateAsync with an action listener bind.  
So I 'm calling a delete Async onResponse AND onFailure of previous async update but delete async is not excecuted correctly.  
I got exception  
`Request cannot be executed i/o reactor status stopped  
Thnx in advance for your help

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 26, 2021, 10:23pm UTC](https://discuss.elastic.co/t/delete-async-on-response-of-update-async-does-not-work/287724/2 "2021-10-26T22:23:24Z")

</div>

It'd be useful if you could provide the request you are making, as well as the complete response you received.

---

<div class="post-metadata">

**Author:** ![Giovanni\_Di\_Lembo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/giovanni_di_lembo/32/45714_2.png) [@Giovanni\_Di\_Lembo](https://discuss.elastic.co/u/Giovanni_Di_Lembo)\
**Post date:** [October 27, 2021, 6:03am UTC](https://discuss.elastic.co/t/delete-async-on-response-of-update-async-does-not-work/287724/3 "2021-10-27T06:03:29Z")

</div>

I can post you my code implementation

```auto
 public void updateByQueryRequestFinal(
            final long fromMillis,
          final String indexName, String dateFormat) throws IOException {
    String dateFormatted = DateHelper.format(new Date(fromMillis), dateFormat);
    log.debug("BEGIN updateByQueryRequestFinal from date {} on index:{}",
            dateFormatted, indexName);
    UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest(indexName);
    updateByQueryRequest.setScript(
            new Script(
                    ScriptType.INLINE, "painless",
                    "if (ctx._source.activities!=null) \n" +
                            " { \n" +
                            " ArrayList activities=ctx._source.activities;\n" +
                            " for (int i=activities.length-1; i>=0; i--) {\n" +
                            " if (activities[i].creationDate.compareTo('"+dateFormatted+"')<=0) {\n" +
                            " activities.remove(i);\n" +
                            " \n" +
                            " }\n" +
                            " \n" +
                            " }\n" +
                            " \n" +
                            " \n" +
                            " ctx._source.activities=activities;\n" +
                            " \n" +
                            " }",
                    Collections.emptyMap()));
    final ActionListener actionListener = new ActionListener() {

      @SneakyThrows
      @Override
      public void onResponse(final Object o) {
        log.debug("The Old {} correctly updated", indexName);
        deleteByQueryRequestActivitiesEmpty(indexName);
      }

      @Override
      public void onFailure(final Exception e) {
        log.warn("The update of old {} raised an exception:{} ", indexName, e.getCause().toString());
        deleteByQueryRequestActivitiesEmpty(indexName);
      }
    };
    //client.updateByQuery(updateByQueryRequest, RequestOptions.DEFAULT);//,actionListener);
    client.updateByQueryAsync(updateByQueryRequest, RequestOptions.DEFAULT,actionListener);
    log.debug("END updateByQueryRequestFinal on index:{}", indexName);

```

and onFailure or onResponse I call

```auto
public void deleteByQueryRequestActivitiesEmpty(

          final String indexName ) {

    log.debug("BEGIN deleteByQueryRequestActivitiesEmpty on index:{}",
             indexName);
    final DeleteByQueryRequest request =
            new DeleteByQueryRequest(indexName);
    request.setTimeout(TimeValue.timeValueMinutes(60));
    request.setRefresh(true);
    final QueryBuilder boolQueryBuilder = new BoolQueryBuilder()
            .mustNot(nestedQuery("activities",existsQuery("activities"), ScoreMode.Total));
    request.setQuery(boolQueryBuilder);
    log.debug("BEGIN deleteByQuery deleting");
    final ActionListener actionListener = new ActionListener() {
      @Override
      public void onResponse(final Object o) {
        log.debug("The Old {} correctly deleted", indexName);
      }

      @Override
      public void onFailure(final Exception e) {
        log.warn("The Deletion of old {} raised an exception:{} ", indexName, e.getCause().toString());
      }
    };
    //client.deleteByQuery(request, RequestOptions.DEFAULT);

    client.deleteByQueryAsync(request, RequestOptions.DEFAULT,actionListener);
    log.debug("END deleteByQueryRequestActivitiesEmpty on index:{}", indexName);
  }

```

The strange thing is that if I excecute them separately, they do their job correctly. It looks something related to RestHighLevelClient (may concurrent usage?)

---

<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:** [November 24, 2021, 6:03am UTC](https://discuss.elastic.co/t/delete-async-on-response-of-update-async-does-not-work/287724/4 "2021-11-24T06:03:54Z")

</div>

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