Delete all documents from index/type without deleting type

后端 未结 15 458
耶瑟儿~
耶瑟儿~ 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:36

    Elasticsearch 2.3 the option

        action.destructive_requires_name: true
    

    in elasticsearch.yml do the trip

        curl -XDELETE http://localhost:9200/twitter/tweet
    
    0 讨论(0)
  • 2020-12-04 10:37

    Starting from Elasticsearch 2.x delete is not anymore allowed, since documents remain in the index causing index corruption.

    0 讨论(0)
  • 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" : [ ]
    }
    
    0 讨论(0)
提交回复
热议问题