【问题标题】:How to update child document in Elastic search using update API?如何使用更新 API 更新弹性搜索中的子文档?
【发布时间】:2014-06-18 09:23:05
【问题描述】:

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

请看下面的例子:

创建子文档

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

得到孩子

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

来源完全错误...

希望有人可以提供帮助 马克

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    改变

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

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

    那个?是查询字符串的开头,一直到结尾。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2017-03-25
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      相关资源
      最近更新 更多