1. 程式人生 > >es 基於groovy指令碼進行操作document

es 基於groovy指令碼進行操作document

es,其實是有個內建的指令碼支援的,可以基於groovy指令碼實現各種各樣的複雜的操作 基於groovy指令碼,如何執行partial update

PUT /index/type/id {     "num":0,     "tags":[] } 1. 內建指令碼 POST /index/type/id/_update {     "script":"ctx._source.num+=1" }

2. 外部指令碼 ctx._source.tags+=new_tag POST /index/type/id/_update {     "script":{         "lang":"groovy",         "file":"test-add-tags",         "params":{             "new_tag":"tag1"         }     } }

3. 用指令碼刪除文件 ctx.op = ctx._source.num == count ? 'delete':'none' POST /index/type/id/_update {     "script":{         "lang":"groovy",         "file":"test-delete-tags",         "params":{             "count":1         }     } }