【发布时间】:2020-07-17 14:31:24
【问题描述】:
我正在尝试从索引中删除所有文档,而不通过 node.js API 删除索引本身。
我正在尝试使用 deleteByQuery,但如何指定索引中的所有文档?
【问题讨论】:
标签: node.js elasticsearch dml elasticsearch-query
我正在尝试从索引中删除所有文档,而不通过 node.js API 删除索引本身。
我正在尝试使用 deleteByQuery,但如何指定索引中的所有文档?
【问题讨论】:
标签: node.js elasticsearch dml elasticsearch-query
您可以简单地使用 REST API 从您的索引中删除所有文档,因为您不需要使用 node.js API,您可以直接点击下面的 API。 More info on delete all docs examples and different options
POST <your-index-name>/_delete_by_query
{
"query": {
"match_all": {} --> this matches all docs in index, hence deletes all of them.
}
}
Curl 格式作为 POST 请求,因此很难与 rest-client 一起使用
curl -X POST "localhost:9200/<your-index-name>/_delete_by_query" -H 'Content-Type: application/json' -d'
{
"query": {
"match_all": {}
}
}
'
【讨论】:
9200 端口上运行
感谢@opster.... 我一直在寻找纯 node.js 解决方案,终于找到了。 我想发布它,因为我从未在网上看到过这段代码 sn-p。
_
在使用 axios 的客户端上:
axios({
method: 'post',
url: '/empty_index',
}).then();
_
在服务器上我的快速路线
app.post( '/empty_index', function( req, res, next ) {
const client = new Client({
node: 'http://localhost:'+process.env.ELASTICSEARCH_PORT
});
client.deleteByQuery({
index: <your-index-name>,
body: {
query: {
match_all: {}
}
}
}, function (error, response) {
console.log(response);
});
return res.status( 200 ).send();
});
【讨论】:
node.js 来解决它了 :),顺便说一句,你是否使用 REST 或 curl 或 using my postman 集合尝试过,如果你能做到,那就太好了也支持我的回答,您应该使用 node.js 将您的接受标记为它:)