簡體   English   中英

Elasticsearch根據字段值刪除文檔

[英]Elasticsearch delete a document based on a field value

我是Elasticsearch的新手,正在嘗試找出一種刪除包含以時間戳為字段值的文檔的方法。

我有一個文檔,字段名為lastmodifiedtime 該字段的類型為long,用於存儲時間戳(即自EPOCH。ex,1486709502起的毫秒數)。

現在,我有一個用例,需要刪除lastmodifiedtime早於一天的所有文檔。 因此,我找出與一天前時間相對應的timstamp值,然后嘗試刪除文檔。

我嘗試了REST調用,如下所示

DELETE http://localhost:9200/testindex/testtype/_query
"query": {
    "term" : {
        "lastmodifiedtime" : {
        "lte": 1486709504
        }
    }
 }

但是得到以下響應:

{
    "found": false,
    "_index": "testindex",
    "_type": "testtype",
    "_id": "_query",
    "_version": 4,
    "result": "not_found",
    "_shards":
    {
        "total": 2,
        "successful": 1,
        "failed": 0
    }
}

您能幫我如何處理這種情況嗎?

您可以使用delete_by查詢api

POST http://localhost:9200/testindex/testtype/_delete_by_query
{
  "query": {
    "range": {
      "lastmodifiedtime": {
        "lte": 1486709504
      }
    }
  }
}

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM