2015-09-25 123 views
2

我想更新logdate列,以查找特定索引中的所有記錄。從我目前閱讀的內容看來,這似乎是不可能的?我是對的?ElasticSearch中的更新記錄

這裏有一個文件的樣本:

{ 
      "_index": "logstash-01-2015", 
      "_type": "ufdb", 
      "_id": "AU__EvrALg15uxY1Wxf9", 
      "_score": 1, 
      "_source": { 
       "message": "2015-08-14 06:50:05 [31946] PASS level2  10.249.10.70 level2  ads  http://ad.360yield.com/unpixel.... GET", 
       "@version": "1", 
       "@timestamp": "2015-09-24T11:17:57.389Z", 
       "type": "ufdb", 
       "file": "/usr/local/ufdbguard/logs/ufdbguardd.log", 
       "host": "PROXY-DEV", 
       "offset": "3983281700", 
       "logdate": "2015-08-14T04:50:05.000Z", 
       "status": "PASS", 
       "group": "level2", 
       "clientip": "10.249.10.70", 
       "category": "ads", 
       "url": "http://ad.360yield.com/unpixel....", 
       "method": "GET", 
       "tags": [ 
        "_grokparsefailure" 
       ] 
      } 
     } 
+0

你是什麼意思的「更新」?將值更改爲其他字符串?將它轉換爲日期對象而不是字符串?將該值複製到@timestamp?要麼 ? –

+0

我希望將logdate字段更改爲所有文檔的另一個日期。在MySQL中,我會這樣做: 'UPDATE logstash SET logdate =「2015-09-20T04:50:05.000Z」' 但是它的ElasticSearch似乎只能通過提供它的_id來更新一個文檔。 –

回答

1

你是正確的,這是不可能的。

長期以來一直存在一個公開的問題,要求Update by Query,我不確定它會在很短的時間內實現,因爲它對於底層lucene引擎是非常有問題的。它要求刪除所有文件並重新索引它們。

一個Update by Query Plugin在github上可用,但它是實驗性的,我從來沒有嘗試過。

0

可以使用partial update API

爲了測試它,我創建了一個簡單的指標:

PUT /test_index 

然後創建一個文檔:

PUT /test_index/doc/1 
{ 
    "message": "2015-08-14 06:50:05 [31946] PASS level2  10.249.10.70 level2  ads  http://ad.360yield.com/unpixel.... GET", 
    "@version": "1", 
    "@timestamp": "2015-09-24T11:17:57.389Z", 
    "type": "ufdb", 
    "file": "/usr/local/ufdbguard/logs/ufdbguardd.log", 
    "host": "PROXY-DEV", 
    "offset": "3983281700", 
    "logdate": "2015-08-14T04:50:05.000Z", 
    "status": "PASS", 
    "group": "level2", 
    "clientip": "10.249.10.70", 
    "category": "ads", 
    "url": "http://ad.360yield.com/unpixel....", 
    "method": "GET", 
    "tags": [ 
     "_grokparsefailure" 
    ] 
} 

現在我可以做一個部分更新的文件有:

POST /test_index/doc/1/_update 
{ 
    "doc": { 
     "logdate": "2015-09-25T12:20:00.000Z" 
    } 
} 

如果我檢索文檔:

GET /test_index/doc/1 

我會看到logdate屬性已更新:

{ 
    "_index": "test_index", 
    "_type": "doc", 
    "_id": "1", 
    "_version": 2, 
    "found": true, 
    "_source": { 
     "message": "2015-08-14 06:50:05 [31946] PASS level2  10.249.10.70 level2  ads  http://ad.360yield.com/unpixel.... GET", 
     "@version": "1", 
     "@timestamp": "2015-09-24T11:17:57.389Z", 
     "type": "ufdb", 
     "file": "/usr/local/ufdbguard/logs/ufdbguardd.log", 
     "host": "PROXY-DEV", 
     "offset": "3983281700", 
     "logdate": "2015-09-25T12:20:00.000Z", 
     "status": "PASS", 
     "group": "level2", 
     "clientip": "10.249.10.70", 
     "category": "ads", 
     "url": "http://ad.360yield.com/unpixel....", 
     "method": "GET", 
     "tags": [ 
     "_grokparsefailure" 
     ] 
    } 
} 

這裏是我用來測試它的代碼:

http://sense.qbox.io/gist/236bf271df6d867f5f0c87eacab592e41d3095cf

+1

感謝您的回答。我想我沒有正確解釋。我已經檢查過更新API,但是我可以看到的是,您必須提供_id字段才能運行更新。就我而言,我喜歡在所有文檔上運行更新以使「logdate」相同。 –