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

Elastic search,是否可以在不更新整个文档的情况下更新嵌套对象?

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

Elastic search,是否可以在不更新整个文档的情况下更新嵌套对象?

您可以使用Update API。

curl -XPOST localhost:9200/docs/posts/post/_update -d '{    "script" : "ctx._source.nested_user = updated_nested_user",    "params" : {        "updated_nested_user" : {"field": "updated"}    }}'

需要注意的是更新脚本支持条件逻辑,如图所示这里。因此,您可以在用户更改时标记论坛帖子,然后遍历帖子以仅更新具有更改用户的帖子。

curl -XPOST 'localhost:9200/docs/posts/post/_update' -d '{    "script" : "ctx._source.tags.contains(tag) ? "ctx._source.nested_user = updated_nested_John" : ctx.op = "none"",    "params" : {        "tag": "updated_John_tag",        "updated_nested_John" : {"field": "updated"}    }}'

更新

也许我的三元运算符示例不完整。问题中没有提到这一点,但是假设用户在应用程序的单独部分中更改了他们的信息,最好将这些更改以一个脚本应用于论坛帖子。代替使用标签,尝试直接检查用户字段中的更改:

curl -XPOST 'localhost:9200/docs/posts/post/_update' -d '{    "script" : "ctx._source.nested_user.contains(user) ? "ctx._source.nested_user = updated_nested_John" : ctx.op = "none"",    "params" : {        "user": "John",        "updated_nested_John" : {"field": "updated"}    }}'

如上所述,这可能比重新索引完整帖子的速度要慢。



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

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

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