elasticsearch,nest,.net,elasticsearch,Nest" /> elasticsearch,nest,.net,elasticsearch,Nest" />

.net 更新Elasticsearch中的嵌套数组

.net 更新Elasticsearch中的嵌套数组,.net,elasticsearch,nest,.net,elasticsearch,Nest,我是elasticsearch的新手,我正在尝试为elasticsearch中的upsert数据建立一个项目。我有以下文档: { "PropertyOne": "propertyone", "PropertyTwo": "propertytwo", "MyArray": [ { "FirstObjArrayPropertyOne": "ArrayPropertyOne", "FirstObjArrayPropertyTwo": "ArrayPr

我是elasticsearch的新手,我正在尝试为elasticsearch中的upsert数据建立一个项目。我有以下文档:

{
"PropertyOne": "propertyone",
  "PropertyTwo": "propertytwo",
  "MyArray": [
      {
        "FirstObjArrayPropertyOne": "ArrayPropertyOne",
        "FirstObjArrayPropertyTwo": "ArrayPropertyTwo",
      },
      {
        "SecondObjArrayPropertyOne": "ArrayPropertyOne",
        "SecondObjArrayPropertyTwo": "ArrayPropertyTwo",
      }
    ]
}
现在我想替换“MyArray”的值,它看起来像:

{
 "PropertyOne": "propertyone",
  "PropertyTwo": "propertytwo",
  "MyArray": [
      {
        "NewObjectOne": "ArrayPropertyOne",
        "NewObjectOne": "ArrayPropertyTwo"
      },
      {
        "NewObjectTwo": "ArrayPropertyOne",
        "NewObjectTwo": "ArrayPropertyTwo"
      },
      {
        "NewObjectThree": "ArrayPropertyOne",
        "NewObjectThree": "ArrayPropertyTwo"
      }
    ]
}
我使用.NET的Nest Api,创建了一个无痛的脚本,如下所示

ctx._source.MyArray = [
  {
    "NewObjectOne": "ArrayPropertyOne",
    "NewObjectOne": "ArrayPropertyTwo"
  },
  {
    "NewObjectTwo": "ArrayPropertyOne",
    "NewObjectTwo": "ArrayPropertyTwo"
  },
  {
    "NewObjectThree": "ArrayPropertyOne",
    "NewObjectThree": "ArrayPropertyTwo"
  }
]
错误是

{Type: script_exception Reason: "compile error" CausedBy: "Type: illegal_argument_exception Reason: "invalid sequence of tokens near ['{']." CausedBy: "Type: no_viable_alt_exception Reason: """"}
有什么建议吗


感谢您的建议

您的映射是什么样子的?您可以在尝试为文档编制索引时共享代码吗?请查看中的示例无痛脚本(最后一个示例)。这是对现有数组的附加,但只需对脚本进行一点小的更改,您就可以覆盖该数组。的可能重复