Update Query not working in Elastic 7

I am trying to update(POST) a elastic record using below query but i am getting back a weird error.

Request:

_update_by_query

{
  "script": "{ctx._source.orderDocuments[0] = newobj};",
  "params": {
    "newobj": {
      "orderId": 16475382,
      "documentCategoryCode": "INVOICEPACKET",
      "fileId": "7f991422-dd9a-4c1d-8562-eea575e28bb2",
      "name": "CustomerInvoicePacket_9661151"
    }
  },
  "lang": "painless",
  "query": {
    "match": {
      "_id": "FO-5427880"
    }
  }
}

Result:

{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "Unknown key for a START_OBJECT in [params].",
"line": 1,
"col": 50
}
],
"type": "parsing_exception",
"reason": "Unknown key for a START_OBJECT in [params].",
"line": 1,
"col": 50
},
"status": 400
}

Can someone help me with whatever i am missing?

Welcome!

I don't think you can pass a full object as a param but only flat values, like:

{
  "script": "ctx._source.orderDocuments[0].orderId = params.orderId;ctx._source.orderDocuments[0].documentCategoryCode = params.documentCategoryCode;",
  "params": {
      "orderId": 16475382,
      "documentCategoryCode": "INVOICEPACKET",
      "fileId": "7f991422-dd9a-4c1d-8562-eea575e28bb2",
      "name": "CustomerInvoicePacket_9661151"
  },
  "lang": "painless",
  "query": {
    "match": {
      "_id": "FO-5427880"
    }
  }
}

Hi,
I tried this approach but i am still getting the same parse error as reported on the initial post. Just to let you know, ctx._source.orderDocuments is currently empty and i am trying to populate/update the empty array using the query above.

It's the same exact error?

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

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