Skip to content

Instantly share code, notes, and snippets.

@webmusing
Created January 3, 2013 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webmusing/7f0e6c996d9c4cc512ec to your computer and use it in GitHub Desktop.
Save webmusing/7f0e6c996d9c4cc512ec to your computer and use it in GitHub Desktop.
Error in updating an existing document field count in Elasticsearch
var options = {
host: 'localhost',
port: '9200',
path: 'prototype_2013.01.03/chow-clfg/Nx4JcvyxTPujkyy0Jq5BNw/_update?parent=chow-demo',
method: 'POST'
};
var script = 'ctx._source[\"chow-clfg\"].count+=num';
var data = '{"script":"'+script+'","params":{"num":1}}';
data = JSON.parse(data);
var req = http.request(options, function(res){
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log(chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.write(data);
req.end();
// Returns result
{"script":"ctx._source["chow-clfg"].count+=num","params":{"num":1}}
^
SyntaxError: Unexpected token c
at Object.parse (native)
at ElasticSearchCall.<anonymous> (/home/plumbline/Applications/nodejs/node-v0.8.14/prototype.js:136:20)
at ElasticSearchCall.EventEmitter.emit (events.js:96:17)
at IncomingMessage.ElasticSearchCall.exec (/home/plumbline/Applications/nodejs/node-v0.8.14/node_modules/elasticsearchclient/lib/elasticsearchclient/calls/elasticSearchCall.js:49:18)
at IncomingMessage.EventEmitter.emit (events.js:126:20)
at IncomingMessage._emitEnd (http.js:366:10)
at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:149:23)
at Socket.socketOnData [as ondata] (http.js:1367:20)
at TCP.onread (net.js:403:27)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment