node.js - Update elasticsearch doc via node js api -
i trying update doc particular id via node.js api in elasticsearch. new node.js, can't figure out why update fails. here relevant snipet webapp.js file:
app.post('/api/resources/:id', function(req, res) { var resource = req.body; var param = { index: 'test', type: 'tes', _id : req.params.id, doc:resource }; console.log("modifying resource:", req.params.id, resource); client.update(param, function (error, response) { // client.get({ index: 'test', type: 'tes', id: req.params.id }, function(err, resource) { res.send(response); }); // }); }); i testing via curl command line using command :
curl -v \ --data '{"name":"xxx"}' \ http://localhost:3000/api/resources/av2ebdzxwll5fjupdx0r here response receive command line:
* trying ::1... * tcp_nodelay set * connected localhost (::1) port 3000 (#0) > post /api/resources/av2ebdzxwll5fjupdx0r http/1.1 > host: localhost:3000 > user-agent: curl/7.51.0 > accept: */* > content-length: 81 > content-type: application/x-www-form-urlencoded > * upload sent off: 81 out of 81 bytes < http/1.1 200 ok < x-powered-by: express < date: fri, 28 jul 2017 16:40:53 gmt < connection: keep-alive < content-length: 0 < * curl_http_done: called premature == 0 * connection #0 host localhost left intact the document not getting updated. can me figure out doing wrong here.
your param hash not correct, _id should id , doc should body. thing partial update, need enclose partial fields in doc structure:
var resource = {doc: req.body}; var param = { index: 'test', type: 'tes', id: req.params.id, body: resource } ^ ^ | | change these 2 params see official documentation here
Comments
Post a Comment