0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Elasticsearchでcurlとqueryを使ったドキュメントの削除

Last updated at Posted at 2018-04-06

  • 業務でElasticsearchのデータ削除の機会があったので日本語でメモ。
# queryの条件にhitするドキュメントを削除
curl -XDELETE localhost:9200/index_name/type_name/_query?pretty=true -d '{{ 削除したい条件のquery }}'

※もちろんlocalhost:9200, inedex_name, type_nameはそれぞれの環境に合わせて変更


# delete_ngというフィールドが存在しないドキュメントの検索
GET index_name/type_name/_search
{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "missing": {
                "field": "delete_ng"
              }
            }
          ]
        }
      }
    }
  }
}

これを削除したかったら、下記のcurlで削除可能。


リクエスト

curl -XDELETE localhost:9200/index_name/type_name/_query -d '{"query":{"filtered":{"filter":{"bool":{"must":[{"missing":{"field":"delete_ng"}}]}}}}}'

レスポンス

{
  "_indices" : {
    "index_name" : {
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "failed" : 0
      }
    }
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?