ncb000gt / node-es

NodeJS module for ElasticSearch.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Version not passed?

joafeldmann opened this issue · comments

I am trying to use the versioning feature and therefore I am passing the doc version with the update query:

var elasticsearch = new ESClient();
elasticsearch.request.on('request', function (options) {
    console.log(options.path);
});
elasticsearch.update({
        _index: 'my_index',
        _type: 'my_type',
        _id: 'lJ5P4EFBN',
        version: 5
    }, {
        doc: {
            name: 'new-name-should-not-work'
        }
    },
    function(err, result) {
        console.dir(err);
    }
);

The logged path is: /my_index/my_type/lJ5P4EFBN/_update?version=5

Since the version number of the doc is higher than 5 this should raise an error, but the update is working. When I use curl requests I get the version conflict errors as expected:

curl -XPUT localhost:9200/my_index/my_type/lJ5P4EFBN?version=5 -d '{
    "name" : "new-name"
}'
OR
curl -XPOST localhost:9200/my_index/my_type/lJ5P4EFBN?version=5 -d '{
    "name" : "new-name"
}'

This is an interesting one... I've written some tests to confirm how ElasticSearch behaves when using update to modify a document with a version and from what I've found, the update API method doesn't accept version. Only index accepts version (which is confirmed by your curl commands as well).

var elasticsearch = new ESClient();
elasticsearch.request.on('request', function (options) {
    console.log(options.path);
});

elasticsearch.index({
        _index: 'my_index',
        _type: 'my_type',
        _id: 'lJ5P4EFBN',
        version: 5
    }, {
        name: 'new-name-should-not-work'
    },
    function(err, result) {
        console.dir(err);
    }
);

The above code (notice update has been changed to index) will result in the following path: /my_index/my_type/lJ5P4EFBN?version=5

This matches the path you are doing curl PUT and POST to and it also properly throws a version mismatch error. The downside is that if you pass the appropriate version number (which is required for the PUT or POST to work), the document will be wholly replaced with what you supply as the document argument to the index function.

The update method simply ignores version on input and ups the version number internally after making the specified update thus bypassing any conflict checks entirely. According to documentation at http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-update.html#docs-update, the following additional parameters are accepted:

  • routing
  • parent
  • timeout
  • replication
  • consistency
  • percolate
  • refresh
  • fields

TL;DR: Unfortunately, version doesn't appear to be supported for update. But you could use the index command with version provided that you specify the entire document (not just the fields you are looking to update).

You're right, thanks. Versioning and _update is not yet supported. The feature is implemented and documented (!), but will be available only in the next master release (1.0). For more details see: https://groups.google.com/d/msg/elasticsearch/_3kgTHs0oow/QB5MAXLHOioJ