0

I'm new to elasticsearch and I'm tryng to set-up a project for upsert data in elastisearch I have the following document:

{
"PropertyOne": "propertyone",
  "PropertyTwo": "propertytwo",
  "MyArray": [
      {
        "FirstObjArrayPropertyOne": "ArrayPropertyOne",
        "FirstObjArrayPropertyTwo": "ArrayPropertyTwo",
      },
      {
        "SecondObjArrayPropertyOne": "ArrayPropertyOne",
        "SecondObjArrayPropertyTwo": "ArrayPropertyTwo",
      }
    ]
}

Now I would like to replace the value of "MyArray" and it will looks like:

{
 "PropertyOne": "propertyone",
  "PropertyTwo": "propertytwo",
  "MyArray": [
      {
        "NewObjectOne": "ArrayPropertyOne",
        "NewObjectOne": "ArrayPropertyTwo"
      },
      {
        "NewObjectTwo": "ArrayPropertyOne",
        "NewObjectTwo": "ArrayPropertyTwo"
      },
      {
        "NewObjectThree": "ArrayPropertyOne",
        "NewObjectThree": "ArrayPropertyTwo"
      }
    ]
}

I use Nest Api for .NET and I create a painless script as follow

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

And the error is

{Type: script_exception Reason: "compile error" CausedBy: "Type: illegal_argument_exception Reason: "invalid sequence of tokens near ['{']." CausedBy: "Type: no_viable_alt_exception Reason: """"}

Any suggestions?

Thanks in advice

3
  • What is your mapping look like ? And could you share the code while you are trying to index the document ? Commented Mar 17, 2017 at 11:36
  • 1
    Check out the example Painless script in stackoverflow.com/a/42800992/1831 (last example). This is appending to an existing array, but with a small change to the script you can overwrite the array instead. Commented Mar 17, 2017 at 20:55
  • Possible duplicate of ElasticSearch - Add element inside nested List<T> using NEST 5.x Commented Mar 20, 2017 at 21:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.