elasticsearch - 如何使用更新 API 更新 Elastic search 中的子文档?

标签 elasticsearch

我在 Elastic Search 中使用父子文档。我可以使用 _update api 对主文档进行部分更新。但是,如果我在子文档上使用 _update APi,则该文档的内容将完全被我的脚本内容替换。出了问题......我不知道是什么......

参见下面的示例:

创建子文档

POST to /indexName/comment/c006?parent=b003
{
  "authorId": "ps101",
  "authorFullName": "Lieven",
  "body": "Comment text comes here",
  "isApproved": false
}

获取 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
   }
}

现在,重新找回 child

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
   }
  }
}

来源完全错误......

希望有人能帮忙 马克

最佳答案

改变

POST TO /indexName/comment/c006?parent=b003/_update

POST TO /indexName/comment/c006/_update?parent=b003

那个?是查询字符串的开头,它位于末尾。

关于elasticsearch - 如何使用更新 API 更新 Elastic search 中的子文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24221102/

相关文章:

elasticsearch - 嵌套对象和聚合

Elasticsearch 推荐图书作者 : how to limit maximum 3 books per author?

hadoop - 使用来自Pig的EShadoop将Geoshape存储到Elasticsearch

spring-boot - Spring Boot +休眠搜索:必需的索引状态被忽略?

ElasticSearch 结果不相关

php - symfony2 FOSElasticaBundle:当Elasticsearch服务关闭时,如何推迟文档更新?

elasticsearch - 如何在不同的计算机上运行elasticsearch服务器?

python - 错误号 111 : Connection refused when connecting to Elasticsearch with Python Script

docker - 使用 NEST 访问 Elasticsearch Docker 实例

java - Elasticsearch 6.4.2 的 Spring 数据不适用于 Java hashmap 属性