我知道可以通过deleteByQuery删除某种类型的所有文档.
例:
curl -XDELETE 'http://localhost:9200/twitter/tweet/_query' -d '{
"query" : {
"term" : { "user" : "kimchy" }
}
}'
Run Code Online (Sandbox Code Playgroud)
但我没有任何条款,只是想删除该类型的所有文件,无论什么条款.实现这一目标的最佳做法是什么?空术语不起作用.
Joh*_*one 167
我相信如果你把查询删除和匹配结合在一起它应该做你想要的,就像这样(使用你的例子):
curl -XDELETE 'http://localhost:9200/twitter/tweet/_query' -d '{
"query" : {
"match_all" : {}
}
}'
Run Code Online (Sandbox Code Playgroud)
或者您可以删除类型:
curl -XDELETE http://localhost:9200/twitter/tweet
Run Code Online (Sandbox Code Playgroud)
Iqb*_*bal 66
已删除Delete-By-Query插件,支持在核心中使用新的Delete By Query API实现.在这里阅读
curl -XPOST 'localhost:9200/twitter/tweet/_delete_by_query?conflicts=proceed&pretty' -d'
{
"query": {
"match_all": {}
}
}'
Run Code Online (Sandbox Code Playgroud)
Jay*_*hah 56
从ElasticSearch 5.x开始,默认情况下会出现delete_by_query API
POST: http://localhost:9200/index/type/_delete_by_query
{
"query": {
"match_all": {}
}
}
Run Code Online (Sandbox Code Playgroud)
use*_*829 20
自 ElasticSearch 7.x 起,delete-by-query插件已被删除,取而代之的是新的“按查询删除”API。
卷曲选项:
curl -X POST "localhost:9200/my-index/_delete_by_query" -H 'Content-Type: application/json' -d' { "query": { "match_all":{} } } '
Run Code Online (Sandbox Code Playgroud)
或者在基巴纳
POST /my-index/_delete_by_query
{
"query": {
"match_all":{}
}
}
Run Code Online (Sandbox Code Playgroud)
Bri*_*edt 16
Torsten Engelbrecht对John Petrones的评论得到了扩展:
curl -XDELETE 'http://localhost:9200/twitter/tweet/_query' -d
'{
"query":
{
"match_all": {}
}
}'
Run Code Online (Sandbox Code Playgroud)
(我不想编辑John的回复,因为它得到了upvotes并被设置为答案,我可能已经引入了错误)
Luk*_*ina 15
您可以使用以下查询从类型中删除文档:
POST /index/type/_delete_by_query
{
"query" : {
"match_all" : {}
}
}
Run Code Online (Sandbox Code Playgroud)
我在Kibana和Elastic 5.5.2中测试了这个查询
由于对Elasticsearch REST请求进行严格的内容类型检查,以上答案不再适用于ES 6.2.2 。curl我最终使用的命令是这样的:
curl -H'Content-Type: application/json' -XPOST 'localhost:9200/yourindex/_doc/_delete_by_query?conflicts=proceed' -d' { "query": { "match_all": {} }}'
Run Code Online (Sandbox Code Playgroud)
在Kibana控制台中:
POST calls-xin-test-2/_delete_by_query
{
"query": {
"match_all": {}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
(声誉不够高,无法发表评论)John Petrone 答案的第二部分有效 - 无需查询。它将删除该类型以及该类型中包含的所有文档,但只要您将新文档索引到该类型,就可以重新创建该类型。
只是为了澄清:
$ curl -XDELETE 'http://localhost:9200/twitter/tweet'
注意:这会删除映射!但如前所述,可以通过创建新文档轻松地重新映射它。
注意ES2 +
从ES 1.5.3开始,不推荐使用逐个查询API,并且自ES 2.0以来已完全删除
而不是API,Delete By Query现在是一个插件.
要使用"按查询删除"插件,必须在群集的所有节点上安装插件:
sudo bin/plugin install delete-by-query
Run Code Online (Sandbox Code Playgroud)
安装后必须重新启动所有节点.
该插件的用法与旧API相同.您无需更改查询中的任何内容 - 此插件只会使它们正常工作.
您有以下选择:
1)删除整个索引:
curl -XDELETE 'http://localhost:9200/indexName'
Run Code Online (Sandbox Code Playgroud)
例:
curl -XDELETE 'http://localhost:9200/mentorz'
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请单击此处-https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html
2)通过查询删除符合条件的内容:
curl -XDELETE 'http://localhost:9200/mentorz/users/_query' -d
'{
"query":
{
"match_all": {}
}
}'
Run Code Online (Sandbox Code Playgroud)
*这里mentorz是索引名称,users是类型
我正在使用elasticsearch 7.5,当我使用
curl -XPOST 'localhost:9200/materials/_delete_by_query?conflicts=proceed&pretty' -d'
{
"query": {
"match_all": {}
}
}'
Run Code Online (Sandbox Code Playgroud)
这将引发以下错误。
{
"error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
"status" : 406
}
Run Code Online (Sandbox Code Playgroud)
我还需要-H 'Content-Type: application/json'在请求中添加额外的标头以使其正常工作。
curl -XPOST 'localhost:9200/materials/_delete_by_query?conflicts=proceed&pretty' -H 'Content-Type: application/json' -d'
{
"query": {
"match_all": {}
}
}'
{
"took" : 465,
"timed_out" : false,
"total" : 2275,
"deleted" : 2275,
"batches" : 3,
"version_conflicts" : 0,
"noops" : 0,
"retries" : {
"bulk" : 0,
"search" : 0
},
"throttled_millis" : 0,
"requests_per_second" : -1.0,
"throttled_until_millis" : 0,
"failures" : [ ]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
167246 次 |
| 最近记录: |