您可以使用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"} }}'如上所述,这可能比重新索引完整帖子的速度要慢。



