node-elasticsearch-client icon indicating copy to clipboard operation
node-elasticsearch-client copied to clipboard

Support Upserts to ElasticSearch

Open baxford opened this issue 13 years ago • 7 comments

I've added a function to core.js to allow upserts into elastic search. I'm not sure if this is the best way to do it, but I've added parameters for script, params and the document separately. Hope this is helpful, any comments on it would be welcomed :)

baxford avatar Feb 13 '13 23:02 baxford

Care to add test cases?

juzerali avatar Feb 14 '13 04:02 juzerali

sure, I can do that, I'll put some in :)

baxford avatar Feb 14 '13 05:02 baxford

By the way does ElasticSearch provides an api called upsert, or is it a borrowed term from mongodb or some other document based database?

juzerali avatar Feb 15 '13 21:02 juzerali

yes, I think it's a relatively new feature, if you look at the guide, it's the last example: http://www.elasticsearch.org/guide/reference/api/update.html

Here are some other discussions on it: http://elasticsearch-users.115913.n3.nabble.com/Upsert-Examples-td4027184.html

regards, Bob Axford

Bob Axford M: 0413 770 149 E: [email protected]

On Sat, Feb 16, 2013 at 8:07 AM, Juzer Ali [email protected] wrote:

By the way does ElasticSearch an api called upsert, or is it a borrowed term from mongodb or some other document based database?

— Reply to this email directly or view it on GitHubhttps://github.com/phillro/node-elasticsearch-client/pull/52#issuecomment-13628063.

baxford avatar Feb 15 '13 22:02 baxford

ps will look at test cases early next week

regards, Bob Axford

Bob Axford M: 0413 770 149 E: [email protected]

On Sat, Feb 16, 2013 at 9:24 AM, Bob Axford [email protected] wrote:

yes, I think it's a relatively new feature, if you look at the guide, it's the last example: http://www.elasticsearch.org/guide/reference/api/update.html

Here are some other discussions on it:

http://elasticsearch-users.115913.n3.nabble.com/Upsert-Examples-td4027184.html

regards, Bob Axford

Bob Axford M: 0413 770 149 E: [email protected]

On Sat, Feb 16, 2013 at 8:07 AM, Juzer Ali [email protected]:

By the way does ElasticSearch an api called upsert, or is it a borrowed term from mongodb or some other document based database?

— Reply to this email directly or view it on GitHubhttps://github.com/phillro/node-elasticsearch-client/pull/52#issuecomment-13628063.

baxford avatar Feb 15 '13 22:02 baxford

Hi,

I've added test cases for the upsert functionality, please let me know how this looks and if you'd like anything else.

cheers Bob.

baxford avatar Feb 18 '13 00:02 baxford

Hi, I had a problem that update did fail always "Error missing doc" on ES 0.90.5. So I improved the function and included "upsert". To avoid trouble with old version with npm install I defined the prototype function in my program code. But it would be nice to get it merged here.

var ElasticSearchClient = require('elasticsearchclient');
ElasticSearchClient.prototype.update = function(indexName, typeName, documentId, document, options, cb) {
    //Pull the callback and set it false to not clobber id.
    if(typeof arguments[arguments.length-1]=='function'){
        cb=arguments[arguments.length-1];
        arguments[arguments.length-1]=false;
    }
    document = document || {};
    document = {"doc": document, "doc_as_upsert":true}
    var path = '/' + indexName + '/' + typeName + '/'+documentId+'/_update';
    var qs = '';
    if (options) {
        qs = querystring.stringify(options)
    }
    if (qs.length > 0) {
        path += "?" + qs;
    }
    return this.createCall({data: JSON.stringify(document), path: path, method: 'POST'}, this.clientOptions, cb);
}

seti123 avatar Nov 27 '13 12:11 seti123