Delete all documents from index/type without deleting type

后端 未结 15 542
耶瑟儿~
耶瑟儿~ 2020-12-04 09:45

I know one can delete all documents from a certain type via deleteByQuery.

Example:

curl -XDELETE \'http://localhost:9200/twitter/tweet/_query\' -d \         


        
15条回答
  •  孤街浪徒
    2020-12-04 10:37

    I'm using elasticsearch 7.5 and when I use

    curl -XPOST 'localhost:9200/materials/_delete_by_query?conflicts=proceed&pretty' -d'
    {
        "query": {
            "match_all": {}
        }
    }'
    

    which will throw below error.

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

    I also need to add extra -H 'Content-Type: application/json' header in the request to make it works.

    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" : [ ]
    }
    

提交回复
热议问题