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