Support Upserts to ElasticSearch
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 :)
Care to add test cases?
sure, I can do that, I'll put some in :)
By the way does ElasticSearch provides an api called upsert, or is it a borrowed term from mongodb or some other document based database?
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.
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.
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.
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);
}