[英]Elasticsearch - How to update document
elasticsearch如何更新文檔? 它會刪除原始文件並制作新文件嗎? 我聽說這就是 nosql 的更新方法。 elasticsearch 和其他 nosql 數據庫一樣嗎? 或者它會替換/插入需要的字段?
例如,我正在使用 Elasticsearh 7.0.0。 首先,我創建了一個文檔,
PUT /employee/_doc/1
{
"first_name" : "John",
"last_name" : "Snow",
"age" : 19,
"about" : "King in the north",
"sex" : "male"
}
然后我通過
POST /employee/_update/1/
{
"doc": {
"first_name" : "Aegon",
"last_name" : "Targaryen",
"skill": "fighting and leading"
}
}
最后,我得到了正確的結果
獲取 /employee/_doc/1
{
"_index" : "employee",
"_type" : "_doc",
"_id" : "1",
"_version" : 9,
"_seq_no" : 11,
"_primary_term" : 1,
"found" : true,
"_source" : {
"first_name" : "Aegon",
"last_name" : "Targaryen",
"age" : 19,
"about" : "King in the north",
"sex" : "male",
"skill" : "fighting and leading"
}
}
對於答案,您可以查看文檔:
除了能夠索引和替換文檔,我們還可以更新文檔。 但請注意,Elasticsearch 實際上並沒有在幕后進行就地更新。 每當我們進行更新時,Elasticsearch 都會刪除舊文檔,然后一次性索引一個新文檔,並將更新應用於它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.