es Update API

2019獨角獸企業重金招聘Python工程師標準>>> hot3.png

es Update API 博客分類: 搜索引擎,爬蟲

The update API allows to update a document based on a script provided. The operation gets the document (collocated with the shard) from the index, runs the script (with optional script language and parameters), and index back the result (also allows to delete, or ignore the operation). It uses versioning to make sure no updates have happened during the "get" and "reindex".

Note, this operation still means full reindex of the document, it just removes some network roundtrips and reduces chances of version conflicts between the get and the index. The _source field need to be enabled for this feature to work.

For example, lets index a simple doc:

curl -XPUT localhost:9200/test/type1/1-d '{"counter":1,"tags":["red"]}'

Scripted updatesedit

Now, we can execute a script that would increment the counter:

curl -XPOST 'localhost:9200/test/type1/1/_update'-d '{"script":{"inline":"ctx._source.counter += count","params":{"count":4}}}'

We can add a tag to the list of tags (note, if the tag exists, it will still add it, since its a list):

curl -XPOST 'localhost:9200/test/type1/1/_update'-d '{"script":{"inline":"ctx._source.tags += tag","params":{"tag":"blue"}}}'

In addition to _source, the following variables are available through the ctx map: _index, _type, _id, _version, _routing, _parent, _timestamp, _ttl.

We can also add a new field to the document:

curl -XPOST 'localhost:9200/test/type1/1/_update'-d '{"script":"ctx._source.name_of_new_field = \"value_of_new_field\""}'

Or remove a field from the document:

curl -XPOST 'localhost:9200/test/type1/1/_update'-d '{"script":"ctx._source.remove(\"name_of_field\")"}'

And, we can even change the operation that is executed. This example deletes the doc if the tags field contain blue, otherwise it does nothing (noop):

curl -XPOST 'localhost:9200/test/type1/1/_update'-d '{"script":{"inline":"ctx._source.tags.contains(tag) ? ctx.op = \"delete\" : ctx.op = \"none\"","params":{"tag":"blue"}}}'

Updates with a partial documentedit

The update API also support passing a partial document, which will be merged into the existing document (simple recursive merge, inner merging of objects, replacing core "keys/values" and arrays). For example:

curl -XPOST 'localhost:9200/test/type1/1/_update'-d '{"doc":{"name":"new_name"}}'

If both doc and script is specified, then doc is ignored. Best is to put your field pairs of the partial document in the script itself.

Detecting noop updatesedit

If doc is specified its value is merged with the existing _source. By default the document is only reindexed if the new _source field differs from the old. Setting detect_noop to false will cause Elasticsearch to always update the document even if it hasn’t changed. For example:

curl -XPOST 'localhost:9200/test/type1/1/_update'-d '{"doc":{"name":"new_name"},"detect_noop":false}'

If name was new_name before the request was sent then document is still reindexed.

Upsertsedit

If the document does not already exist, the contents of the upsert element will be inserted as a new document. If the document does exist, then the script will be executed instead:

curl -XPOST 'localhost:9200/test/type1/1/_update'-d '{"script":{"inline":"ctx._source.counter += count","params":{"count":4}},"upsert":{"counter":1}}'

scripted_upsertedit

If you would like your script to run regardless of whether the document exists or not?—?i.e. the script handles initializing the document instead of the upsert element?—?then set scripted_upsert to true:

curl -XPOST 'localhost:9200/sessions/session/dh3sgudg8gsrgl/_update'-d '{"scripted_upsert":true,"script":{"id":"my_web_session_summariser","params":{"pageViewEvent":{"url":"foo.com/bar","response":404,"time":"2014-01-01 12:32"}}},"upsert":{}}'

doc_as_upsertedit

Instead of sending a partial doc plus an upsert doc, setting doc_as_upsert to true will use the contents of doc as the upsert value:

curl -XPOST 'localhost:9200/test/type1/1/_update'-d '{"doc":{"name":"new_name"},"doc_as_upsert":true}'https://www.elastic.co/guide/en/elasticsearch/reference/2.1/docs-update.html#docs-update

轉載于:https://my.oschina.net/xiaominmin/blog/1597001

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/453206.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/453206.shtml
英文地址,請注明出處:http://en.pswp.cn/news/453206.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

聰明人,容易不務實

聰明人擁有很多優勢。首先,聰明人的邏輯強、思路靈活,理解事物很快,因而經常很有創意。聰明人本身,也因為經常感覺到自己「快速理解、時有創意」的特質,認為沒有什么事情難得倒他。漸漸的,在看待任何事物時…

Linux 線程占用CPU過高定位分析

今天朋友問我一個Linux程序CPU占用漲停了&#xff0c;該如何分析&#xff0c; CPU占用過高&#xff0c;模擬CPU占用過高的情況 先上一段代碼&#xff1a; 1 #include <iostream>2 #include <thread>3 #include <vector>4 5 6 int main(int argc, char **argv…

計算機二級常備知識,2020年計算機二級Office考試必備題庫資料!

考試資料在手&#xff0c;考試不用愁&#xff01;領報名界面顯示計算機二級Office通過率僅21.07%&#xff0c;很多人認為是既費腦子又費時間的考試&#xff0c;可能是方法不對&#xff0c;導致花了很多時間還是考不過&#xff0c;剛剛收到3月考的二級證書啦&#xff0c;馬上還有…

MR作業的提交監控、輸入輸出控制及特性使用

2019獨角獸企業重金招聘Python工程師標準>>> MR作業的提交監控、輸入輸出控制及特性使用 博客分類&#xff1a; hadoop 提交作業并監控 JobClient是用戶作業與JobTracker交互的主要接口&#xff0c;它提供了提交作業&#xff0c;跟蹤作業進度、訪問任務報告及logs、…

ACK和NAK

ACK 英文縮寫: ACKnowledge Character在數據通信傳輸中&#xff0c;接收站發給發送站的一種傳輸控制字符。它表示確認發來的數據已經接受無誤。 NAK 英文縮寫: Negative Acknowledgment是否定應答或者非應答的縮寫。它是一個用于數字通信中確認數據受到但是有小錯誤的信號。

http協議與web本質

當你在瀏覽器地址欄敲入“http://www.csdn.net/”&#xff0c;然后猛按回車&#xff0c;呈現在你面前的&#xff0c;將是csdn的首頁了&#xff08;這真是廢話&#xff0c;你會認為這是理所當然的&#xff09;。作為一個開發者&#xff0c;尤其是web開發人員&#xff0c;我想你有…

計算機科學與技術考研課程安排,計算機科學與技術(0812)碩士研究生培養方案(一)...

一、培養目標本專業培養掌握馬克思主義基本原理、計算機科學與技術基礎理論和系統知識&#xff0c;深入了解國內外計算機科學與技術領域新技術和新動向&#xff0c;具備熟練的編程、測試能力&#xff0c;熟練掌握1門外語并具有較強創新和實踐能力&#xff0c;能夠在計算機科學與…

Docker storage driver 選擇

2019獨角獸企業重金招聘Python工程師標準>>> Docker storage driver 選擇 博客分類&#xff1a; docker 本文的目的是說明&#xff0c;如何在生產環境中選擇Docker 的storage driver。以及對應Linux發行版本下Docker storage driver的配置方法。主要參考&#xff0c…

臨界資源和臨界區

臨界資源&#xff1a; 臨界資源是一次僅允許一個進程使用的共享資源&#xff0c;各進程采取互斥的方式實現共享的資源。 屬于臨界資源的硬件有&#xff0c;打印機&#xff0c;磁帶機等&#xff1b;軟件有消息隊列&#xff0c;變量&#xff0c;數組&#xff0c;緩…

手機網站制作html5,【怎么樣制作手機網站】如何使用dreamweavercs6建立手機網站?織夢手機WAP瀏覽模塊如何制作手機網站?如何制作html5手機頁面?...

【怎么樣制作手機網站】如何使用dreamweavercs6建立手機網站?織夢手機WAP瀏覽模塊如何制作手機網站?如何制作html5手機頁面?下面就和小編一起來看看吧!如何使用dreamweavercs6建立手機網站?制作步驟如下:1。打開DreamweaverCS6軟件&#xff0c;可以在DreamweaverCS6軟件的開…

Docker查看關聯容器的卷宗在本機的存儲位置

docker inspect -f {{.Volumes}} volume1轉載于:https://www.cnblogs.com/toSeeMyDream/p/8623430.html

《那些年啊,那些事——一個程序員的奮斗史》轉載1到7

段伏櫪&#xff0c;一個瘦小&#xff0c;矮小&#xff0c;根本和“帥”這個字粘不上任何關系的普通人。名字的來源在于其多讀了幾年書的老爹&#xff0c;總抱著有一天要出書出名乃至于名流千古的美好理想&#xff0c;但可惜現實總是給予他無情的而又現實的打擊&#xff0c;于是…

如果在docker中部署tomcat,并且部署java應用程序

2019獨角獸企業重金招聘Python工程師標準>>> 如果在docker中部署tomcat,并且部署java應用程序 博客分類&#xff1a; docker 1、先說如何在docker中部署tomcat 第一步&#xff1a;root用戶登錄在系統根目錄下創建文件夾tomcat7,命令如&#xff1a;mkdir tomcat7&…

原語

一般地&#xff0c;把系統態下執行的某些具有特定功能的程序段成為原語。原語有兩種&#xff1a;1是機器指令級的&#xff0c;其特點是執行期間不允許中斷&#xff0c;正如在物理學中的原子一樣&#xff0c;在操作系統中是一個不可分割的基本單位。2是功能型的&#xff0c;其特…

Spring Boot結合thymeleaf

之前在Eclipse里寫了個Spring Boot響應jsp的小demo&#xff0c;后來發現打成jar包導出之后找不到jsp文件了。經過在網上查閱信息與資料&#xff0c;發現Spring Boot對于jsp的支持其實是不好的&#xff0c;而且在一些書中和官方都明確表示沒有辦法支持在jar包中打入jsp文件。雖然…

通信與計算機網絡FSC,數據通信與計算機網絡概述信道習題.pdf

第一章、第二章習題 概述及信道與接口1、目前使用最為普遍的局域網是( )。A. 以太網 B. 標記環網 C.FDDI 網 D.標記總線網2、在 OSI 模型的七層結構中&#xff0c;能進行直接通信的是( )。A. 非同等層間 B. 物理層間 C.數據鏈路層間 D. 網絡層間3、數據通信系統中傳輸的信息稱(…

視覺測量簡介

1.1 視覺測量技術 1.1.1 現代檢測技術的發展趨勢 檢測技術是現代化工業的基礎技術之一&#xff0c;是保證產品質量的關鍵。在現代化的大生產之中&#xff0c;涉及到各種各樣的檢測。隨著工業制造技術和加工工藝的提高和改進&#xff0c;對檢測手段、檢測速度和精度提出了更…

高并發系統之降級特技

2019獨角獸企業重金招聘Python工程師標準>>> 高并發系統之降級特技 博客分類&#xff1a; 架構 在開發高并發系統時有三把利器用來保護系統&#xff1a;緩存、降級和限流。之前已經有一些文章介紹過緩存和限流了。本文將詳細聊聊降級。當訪問量劇增、服務出現問題&a…

處理機的三級調度

在有的操作系統中僅采用一級凋度&#xff0c;而有的操作系統則將凋度分為不同的層次&#xff0c;一個用戶作業從進入系統成為后備作業開始&#xff0c;直到運行結退出系統為止&#xff0c;一般最多經歷三級調度&#xff0c;即處理器調度可以分為以下3個層次。 1.高級調度(High …