# UpdateByQueryRequestBuilder and versionConflicts

**URL:** <https://discuss.elastic.co/t/updatebyqueryrequestbuilder-and-versionconflicts/138234>\
**Category:** Elasticsearch\
**Created:** [July 2, 2018, 2:55pm UTC](https://discuss.elastic.co/t/updatebyqueryrequestbuilder-and-versionconflicts/138234 "2018-07-02T14:55:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![imaad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/imaad/32/48628_2.png) [@imaad](https://discuss.elastic.co/u/imaad)\
**Post date:** [July 2, 2018, 2:55pm UTC](https://discuss.elastic.co/t/updatebyqueryrequestbuilder-and-versionconflicts/138234/1 "2018-07-02T14:55:38Z")

</div>

Hello,

I have a question about the update by query method, in my java application my method look like this :

```
public ActionFuture<BulkByScrollResponse> executeUpdateByQuery(String indexName, Map<String, Object> filterFileds, Map<String, Object> updateFields, Map<String, Object> excludeFileds) throws InterruptedException, ExecutionException {

        Script script = createScript(updateFields);
        LOGGER.info(script.toString());

        BoolQueryBuilder query = ElasticsearchUtils.createQuery(filterFileds, excludeFileds);
        UpdateByQueryAction updateByQueryAction = UpdateByQueryAction.INSTANCE;
        UpdateByQueryRequestBuilder requestBuilder = updateByQueryAction.newRequestBuilder(esClient);
        requestBuilder.abortOnVersionConflict(false).setMaxRetries(5).script(script).filter(query).source(indexName)
                .refresh(true);

        esClient.admin().indices().prepareRefresh(indexName).get();

        LOGGER.info("update request: {}", requestBuilder.source().toString());

        return requestBuilder.execute();
    }

```

My question is about the result of bulkByScrollResponse, when I display the logs sometimes I get a versionConflict not null but my document is succefully updated and sometimes the versionConflict  
is also not null but the document is not updated.

How can I handle this exception correctly?

Thank you for your response

---

<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:** [July 30, 2018, 3:05pm UTC](https://discuss.elastic.co/t/updatebyqueryrequestbuilder-and-versionconflicts/138234/2 "2018-07-30T15:05:00Z")

</div>

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