Painless create new object

I have a rather basic requirement, I would like to add an object to a document with painless within a query for update.

This is the object I would like to add

'"memoire": {
      "codeActe": "C",
      "docType": "M",
      "uuid": "added ",
      "nonFacturable": false,
      "published": false
    }, 

I tried

    POST /csa_encounters/_update_by_query
{
  "script":
{ "source": """

  ctx._source.memoire.codeActe = "C";
  ctx._source.memoire.docType= "M";
  ctx._source.memoire.uuid = "added ";
  ctx._source.memoire.nonFacturable = false;
  ctx._source.memoire.published =false
""",
"lang": "painless"
},
    "query": {
        "bool" : {
            "must" : [
                { "query_string" : { "query" : "140c7646", "fields" : [ "_id" ] } }
            ]
        }
    }
}    

But I get the message null pointer exception as the field does not exist of course

"type": "script_exception",
    "reason": "runtime error",
    "script_stack": [
      "ctx._source.memoire.codeActe = \"C\";\n  ",
      "                   ^---- HERE"
    ],
 ...
    "lang": "painless",
    "caused_by": {
      "type": "null_pointer_exception",
      "reason": null
    }
  },
  "status": 400

I am not able to figure out how to create the object

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.