Upsert With Script

I am trying to write a query to update or insert a document. The query is given below.

POST /abc/_doc/108/_update
{
"script" : {
"source": """
// some process is done here
""",
"lang": "painless",
"params" : {

      **"_source": {**

** "cus": "abcd2"**
** }**
}
},
"scripted_upsert": true,
"upsert": {
"_source": {
** "cus": "abcd2"**
** }**
}
}

I am using the same payload in upsert and inside params
is there a way to use the same payload without writing it twice

If you set scripted_upsert to true (as you're doing already), then you can pass in an empty upsert clause, as shown in the documentation here. The script is then responsible for initializing the document, and you only have to pass in the values inside params.

thank You

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