2016-02-19 76 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')" 
} 

希望这会有所帮助。