【问题标题】:I'm having problems for delating all the documents from an index in elasticsearch without deleting the index我在从弹性搜索中的索引中删除所有文档而不删除索引时遇到问题
【发布时间】:2021-08-13 21:18:02
【问题描述】:

curl -XDELETE "http://localhost:9200/index-consumo_react_mysql/_doc/_query" -d '{"query": {"match_all": {}}}'

错误:

{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您只是缺少 Content-type 标头,还需要将端点更改为_delete_by_query

    curl -XPOST -H "Content-Type: application/json" "http://localhost:9200/index-consumo_react_mysql/_delete_by_query" -d '{"query": {"match_all": {}}}'
    

    【讨论】:

    • {"error":{"root_cause":[{"type":"illegal_argument_exception","re​​ason":"request [DELETE /index-consumo_react_mysql/_doc/_query] 不支持body"}],"type":"illegal_argument_exception","re​​ason":"request [DELETE /index-consumo_react_mysql/_doc/_query] 不支持有body"},"status":400}
    • 我之前证明过,它给了我这些错误。
    • 哦,你运行的是哪个版本?
    • 7.12.1版本。
    • 查看我的更新答案,您使用的端点不正确
    【解决方案2】:

    您可以使用delete_by_query API

    curl -X POST "localhost:9200/<index-name>/_delete_by_query?pretty" -H 'Content-Type: application/json' -d'
    {
      "query": {
        "match_all": {
        }
      }
    }
    '
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-23
      • 2016-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      相关资源
      最近更新 更多