【发布时间】:2017-07-28 16:56:30
【问题描述】:
我正在尝试通过 elasticsearch 中的 Node.js api 更新具有特定 ID 的文档。我是 Node.js 的新手,所以我无法弄清楚更新失败的原因。这是我的webapp.js 文件中的相关片段:
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);
});
// });
});
我正在使用这个命令从命令行通过 curl 进行测试:
curl -v \
--data '{"name":"xxx"}' \
http://localhost:3000/api/resources/AV2EbdzXWlL5FjuPDx0r
这是我从命令行收到的响应:
* Trying ::1...
* TCP_NODELAY set
* Connected to 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 completely 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 to host localhost left intact
文档未更新。有人可以帮我弄清楚我在这里做错了什么。
【问题讨论】:
标签: node.js curl elasticsearch