ElasticSearch批量删除数据

版权声明:转载请注明出处 https://blog.csdn.net/qq_18769269/article/details/87374829

2.x版本

一、
此版本批量删除数据需要安装插件,官方的删除插件
在每一个节点上安装插件:
sudo bin/plugin install delete-by-query
重启elasticsearch

二、
DELETE /twitter/tweet/_query?q=user:kimchy

或者
DELETE /twitter/tweet/_query
{
  "query": {
    "term": {
      "user": "kimchy"
    }
  }
}

{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "pubTime": {
              "gt": "2017-01-01",
              "lt": "2017-02-01"
            }
          }
        }
      ]
    }
  }
}

{

    "took": 293290,
    "timed_out": false,
    "_indices": {
        "_all": {
            "found": 13303,
            "deleted": 13303,
            "missing": 0,
            "failed": 0
        },
        "topcom_yq": {
            "found": 13303,
            "deleted": 13303,
            "missing": 0,
            "failed": 0
        }
    },
    "failures": [ ]

}

使用curl删除的时候时间需要转换成时间戳

curl -XDELETE "192.168.0.161:9200/crawlLog/_query?pretty" -d "
{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "date": {
              "gt": "1505347202560",
              "lt": "1505347202749"
            }
          }
        }
      ]
    }
  }
}"

删除 2017-07-01 之前的数据
curl -XDELETE "10.42.94.189:9200/yuqing/_query?pretty" -d "
{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "pubTime": {
              "lt": "1498867200000"
            }
          }
        }
      ]
    }
  }
}"

猜你喜欢

转载自blog.csdn.net/qq_18769269/article/details/87374829
今日推荐