【问题标题】:How can I delete multiple data in specific index in elasticsearch如何在elasticsearch中删除特定索引中的多个数据
【发布时间】:2017-08-21 13:09:19
【问题描述】:

我需要删除指定索引/类型中的多条记录。我关注这个document 仍然有同样的问题

我需要在 g_visitor 索引中删除 gvisitor 类型中的所有文档,我按照以下命令进行操作

curl -XDELETE http://10.1.2.10:9200/g_visitor/gvisitor

它抛出错误

No handler found for uri [/g_visitor/gvisitor] and method [DELETE]

然后跟着安装Delete By Query插件并尝试删除文档 ,

curl -XDELETE 'http://10.1.2.10:9200/g_visitor/gvisitor/_delete_by_query?conflicts=proceed' -d '{
    "query" : { 
        "match_all" : {}
    }
}'

它抛出错误:

  {
     "found":false,
     "_index":"g_visitor",
     "_type":"gvisitor",
     "_id":"_delete_by_query",
     "_version":1,
     "_shards":{
        "total":2,
        "successful":1,
        "failed":0
     }
  }

建议我,如何在 elasticsearch 中删除特定类型索引中的多个或所有文档。

【问题讨论】:

    标签: curl elasticsearch kibana fluentd


    【解决方案1】:

    您无法删除映射类型,因此您的第一个查询不起作用。

    你只能删除一个索引

    curl -XDELETE http://10.1.2.10:9200/g_visitor
    

    如果你想使用delete-by-query的方式,你可以这样做,但你需要install the plugin first

    sudo bin/plugin install delete-by-query
    

    然后你可以通过调用_query端点(不是_delete_by_query!!)来使用这样的插件:

    curl -XDELETE 'http://10.1.2.10:9200/g_visitor/gvisitor/_query?conflicts=proceed' -d '{
        "query" : { 
            "match_all" : {}
        }
    }'
    

    【讨论】:

    • 我已经安装了delete-by-query 插件并尝试删除上面提到的方式它不适合我
    • 酷,很高兴它有帮助!
    【解决方案2】:

    如果您使用 delete-by-query,则需要使用 terms 而不是 match_all

    curl -XDELETE 'http://10.1.2.10:9200/g_visitor/gvisitor/_delete_by_query?conflicts=proceed' -d '{
        "query" : { 
            "terms" : {}
        }
    }'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-18
      • 2021-10-24
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多