7

https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html

考虑:

PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "user": {
          "type": "nested" 
        }
      }
    }
  }
}

PUT my_index/_doc/1
{
  "group" : "fans",
  "user" : [
    {
      "first" : "John",
      "last" :  "Smith"
    },
    {
      "first" : "Alice",
      "last" :  "White"
    }
  ]
}

当我运行一个无痛的脚本时:

ctx._source.user.add({
    "first" : "Foo",
    "last" : "Bar"
})

它不工作。我试过但找不到其他人发起的任何相关文件或讨论。

4

2 回答 2

12

https://www.elastic.co/guide/en/elasticsearch/reference/5.4/modules-scripting-painless-syntax.html#painless-maps

您可以创建一个地图,['first': 'Foo', 'last': 'Bar', 'sthElse': 100]然后添加它。

所以:

ctx._source.user.add([
    "first" : "Foo",
    "last" : "Bar"
])

请注意,无痛地图可以是混合类型。

于 2018-03-20T06:56:19.603 回答
1
POST my_index/_doc/1/_update
{
   "script": {
      "lang": "painless",
      "inline": "ctx._source.user.add(params.object)",
      "params": {
         "object": {
            "first" : "Foo",
            "last" : "Bar"
         }
      }
   }
}
于 2018-03-20T07:32:20.630 回答