附加到嵌套对象字段

时间:2018-01-29 14:52:26

标签: elasticsearch groovy elastic-stack

我想在更新时附加 elasticsearch 嵌套对象

{
  "_index": "feed",
  "_type": "feed",
  "_id": "41",
  "_version": 1,
  "found": true,
  "_source": {
    "id": 1,
    "name": "Trip to LA",
    "stats": {
      "likes": 40,
      "comments": 50,
     },
  }
}

这是查询

  

POST feed / feed / 41 / _update

{
  "script": { 
    "source" : "ctx._source.stats.add(params.abc)",
    "params": {
      "abc": {
        "likes":1
      }
    }
  }
}

1 个答案:

答案 0 :(得分:1)

用于在嵌套对象中追加

POST Feed / feed / 47 / _update

{
  "script": { 
    "source" : "ctx._source.stats.likes += params.value",
    "params": {
      "value":1
    }
  }
}