我在弹性搜索中使用父子文档。我可以使用_update api对主文档进行部分更新。但是,如果我在子文档上使用_update APi,则文档的内容将完全被我脚本的内容替换。出了点问题......我不知道是什么......
见下面的例子:
创建儿童文件
POST to /indexName/comment/c006?parent=b003
{
"authorId": "ps101",
"authorFullName": "Lieven",
"body": "Comment text comes here",
"isApproved": false
}
GET CHILD
GET to /indexName/comment/c006?parent=b003
{
_index: "indexName"
_type: "comment"
_id: "c006"
_version: 20
found: true
-_source: {
authorId: "ps101"
authorFullName: "Lieven"
body: "Comment text comes here."
isApproved: false
}
}
部分更新
POST TO /indexName/comment/c006?parent=b003/_update
{
"script" : "ctx._source.isAcceptedAnswer=value",
"params" : {
"value" : true
}
}
现在,再来一个孩子
GET to /indexName/comment/c006?parent=b003
{
_index: "indexName"
_type: "comment"
_id: "c006"
_version: 21
found: true
-_source: {
script: "ctx._source.isAcceptedAnswer=value"
-params: {
value: true
}
}
}
来源完全错误......
希望有人可以提供帮助 马克
答案 0 :(得分:5)
更改
POST TO /indexName/comment/c006?parent=b003/_update
到
POST TO /indexName/comment/c006/_update?parent=b003
?是查询字符串的开头,它结束了。