0

I am using Elasticsearch 6.5. I am writing a script for an update API in painless. I need to add structures to an array of structures. If this field does not exist in the document (I can detect that) I am creating a new array with the first element:

ctx._source.myStructArr = new def[] {struct_1};

Later I want to add additional structures:

ctx._source.myStructArr.add(struct_n);

but I receive the following error:

"type": "illegal_argument_exception", "reason": "dynamic method [java.lang.Object[], add/1] not found"

How can I add an element to this array? Or maybe I should create/initialize an array in a different way?

Alessio
  • 3,404
  • 19
  • 35
  • 48
Michał Herman
  • 3,437
  • 6
  • 29
  • 43

1 Answers1

0

Try to use ArrayList instead of new def[].

def arr = new ArrayList();
arr.add(struct_n)

Hope that helps.

Rob
  • 9,664
  • 3
  • 41
  • 43