我正在嘗試將一條記錄插入到 elasticsearch 中,并更新一個現有檔案的欄位,我將從當前記錄中獲取其 _id。網上搜索后發現我們可以使用logstash中的http插件的_update_by_query api。這是下面的配置。
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "my_index_*"
document_id => "%{id_field}"
}
http {
url => "http://localhost:9200/my_index_*/_update_by_query"
http_method => "post"
content_type => "application/json"
format => "message"
message => '{"query":{"match":{"_id":"%{previous_record_id}"}},"script":{"source":"ctx._source.field_to_be_updated=xyz","lang":"painless"}}'
}
}
Elasticsearch 沒有密碼保護,所以我沒有添加授權標頭。但是當我啟動logstash時,當前記錄被插入,但我總是為http插件出現以下錯誤。
2022-05-05T11:31:51,916][ERROR][logstash.outputs.http ][logstash_txe] [HTTP Output Failure] Encountered non-2xx HTTP code 400 {:response_code=>400, :url=>"http://localhost:9200/my_index_*/_update_by_query", :event=>#<LogStash::Event:0x192606f8>}
uj5u.com熱心網友回復:
這不是您應該這樣做的方式,您可以簡單地將elasticsearch輸出用于兩個用例。
第一個用于索引新記錄,接下來的一個用于部分更新 id 為 的另一條記錄previous_record_id。可以在params.event腳本中訪問事件資料:
elasticsearch {
hosts => ["localhost:9200"]
index => "my_index_xyz"
document_id => "%{previous_record_id}"
action => "update"
script => "ctx._source.field_to_be_updated = params.event.xyz"
script_lang => "painless"
script_type => "inline"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/473333.html
標籤:弹性搜索 日志存储 木花 弹性堆栈 logstash-配置
下一篇:如何通過在Elasticsearch1.7中使用“mclaren”搜索來獲取具有:“name”-“McLaren”的索引項?
