2016-02-19 81 views
0

我有以下類型爲'tags'的文檔。現在我想更新文件,即我想刪除標籤「你好」。ElasticSearch使用腳本更新屬性值

{ 
    "id": 1, 
    "tags": [ "hello", "stackoverflow, "promising" ] 
} 

{ 
    "id": 2, 
    "tags": [ "stackoverflow, "promising" ] 
} 

{ 
    "id": 3, 
    "tags": [ "hello" ] 
} 

所以是有可能在ElasticSearch使用一個查詢得到以下結果

{ 
    "id": 1, 
    "tags": [ "stackoverflow, "promising" ] 
} 

{ 
    "id": 2, 
    "tags": [ "stackoverflow, "promising" ] 
} 

{ 
    "id": 3, 
    "tags": [ ] 
} 

回答

0

您需要使用update query plugin這個做。安裝此插件,然後運行以下查詢。

{ 
"query": { 
"match_all": {} 
}, 
"script" : "ctx._source.tags.remove('hello')" 
} 

希望這會有所幫助。