栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从数组elasticsearch中删除对象

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从数组elasticsearch中删除对象

之所以会这样,是因为您尝试在遍历列表时修改列表,这意味着您想要更改对象列表,同时列出这些对象。

相反,您需要这样做:

POST /twitter/twit/1/_update{  "script": "item_to_remove = nil; foreach (item : ctx._source.list) { if (item['tweet_id'] == tweet_id) { item_to_remove=item; } } if (item_to_remove != nil) ctx._source.list.remove(item_to_remove);",  "params": {"tweet_id": "123"}}

如果您有多个符合条件的项目,请改用一个列表:

POST /twitter/twit/1/_update{  "script": "items_to_remove = []; foreach (item : ctx._source.list) { if (item['tweet_id'] == tweet_id) { items_to_remove.add(item); } } foreach (item : items_to_remove) {ctx._source.list.remove(item);}",  "params": {"tweet_id": "123"}}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/388206.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号