Updating Elasticsearch record for a given id gives Error [ ]

Viewed 296

I am trying to update a field in ES record and it errors out.

ES JSON document

{
  "_index": "Barroz",
  "_type": "_doc",
  "_id": "pGcGz3gBRea5RG",
  "_version": 67,
  "_score": 1,
  "_source": {
    "tid": "f90a48519ceeb9e43f21898363b59",
    "taep": "test.treat",
    "cluster": "Barroz.GuardianofDGamasTreasure",
    "state": "Failure",
    "notes": "Looks good"
  }
}

What I am trying:

elastic_client = Elasticsearch(["http://localhost:9200"])

query_body = {"_source": { "state": "Success" } }

elastic_client.update(index="Barroz", doc_type="_doc", id=pGcGz3gBRea5RG, 
body=query_body)

I am getting the below error:

    status_code, error_message, additional_info
elasticsearch.exceptions.RequestError: RequestError(400, 'x_content_parse_exception', 'Unknown key for a VALUE_STRING in [state].')

Please let me know whats the mistake.

1 Answers

The update endpoint accepts the following body, i.e. simply replace _source by doc:

query_body = {"doc": { "state": "Success" } }
Related