# Bulk updating documents - not merging - SOLVED

**URL:** https://discuss.elastic.co/t/bulk-updating-documents-not-merging-solved/27324
**Category:** Elasticsearch
**Created:** [August 13, 2015, 11:41am UTC](https://discuss.elastic.co/t/bulk-updating-documents-not-merging-solved/27324 "2015-08-13T11:41:46Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![simon](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@simon](https://discuss.elastic.co/u/simon)
#### Post date: [August 13, 2015, 11:41am UTC](https://discuss.elastic.co/t/bulk-updating-documents-not-merging-solved/27324/1 "2015-08-13T11:41:47Z")

</div>

Hi,

I am writing a small javascript method to do update by query using the node.js elasticsearch library. Essentially I need to update uuids for records, I have the following so far.

```
   var index = "indexname";
   var eventType = "typeName"
   function migrateId(oldUuid, uuid){
    client.search({
        index: index,
        type: eventType,
        df: 'uuid',
        q: 'uuid:' + oldUuid
    }, function (error, response) {
        console.log(response);

        var updates = [];

        // Iterate through the documents and queue up the updates.
        for(var i = 0, l = response.hits.hits.length; i < l; i++){
            var item = response.hits.hits[i];

            // Tell Elastic we want to update the document
            updates.push({ index: {_index: index, _type: eventType, _id: item._id}});

            // Give it the document to update - will merge with existing.
            updates.push({doc: {uuid: uuid}});
        }

        // Send a bulk update request to elastic search.
        client.bulk({
            body: updates,
            size: 10000
        }, function (err, resp){
            console.log(resp);
        });
    });
}

```

According to the Bulk docs I should expect the documents to merge when I provide the partial update, but this is not the case. On testing, all fields that are not supplied are removed.

## RESOLVED

I've identified the issue. I had set the bulk action to index rather than update. Changing this sorted the problem.

```
            // Tell Elastic we want to update the document
            updates.push({ index: {_index: index, _type: eventType, _id: item._id}});

```

becomes

```
            // Tell Elastic we want to update the document
            updates.push({ update: {_index: index, _type: eventType, _id: item._id}});

```

Simon

---

<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 5, 2017, 11:55pm UTC](https://discuss.elastic.co/t/bulk-updating-documents-not-merging-solved/27324/2 "2017-07-05T23:55:49Z")

</div>


