Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Upserts to ElasticSearch #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

baxford
Copy link

@baxford baxford commented Feb 13, 2013

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 :)

@juzerali
Copy link
Contributor

Care to add test cases?

@baxford
Copy link
Author

baxford commented Feb 14, 2013

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

@juzerali
Copy link
Contributor

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

@baxford
Copy link
Author

baxford commented Feb 15, 2013

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//pull/52#issuecomment-13628063.

@baxford
Copy link
Author

baxford commented Feb 15, 2013

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//pull/52#issuecomment-13628063.

@baxford
Copy link
Author

baxford commented Feb 18, 2013

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.

@seti123
Copy link

seti123 commented Nov 27, 2013

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants