How to Update a Document in Elasticsearch Using the Update API (cURL)

Elasticsearch is a powerful distributed search and analytics engine that stores data in JSON format. It provides REST APIs that allow developers to create, retrieve, update, and delete documents. In this tutorial, we will learn how to update an existing Elasticsearch document using the Update API and cURL. We will use a practical example where we update a document in an Elasticsearch index by adding a cloudpath field containing document paths and their corresponding names. 1. Understanding the Elasticsearch Update Command Let's look at the command:


curl -XPOST \
--header 'Content-Type: application/json' \
http://127.0.0.1:9200/docs_db/_doc/123456/_update \
-d '{
  "doc": {
    "cloudpath": "bin40/ZmxubTU2ODc4ODUwNjU3NjAxODA=.pdf"
  }
}'
Explaination of above command curl is a command-line tool used to communicate with servers through HTTP requests. And we used post method to send update request to server. After that content type header specify which tells Elasticsearch that the request body contains JSON data. After that we have URL and then body which tells to Elastic search which field or data needs to update

FAQ 1.How to partial fields in Elasticsearch? With using update api we can update partial fields in Elasticsearch document. 2.How to verify updated data using the GET API? With get API of elastic search we can retrieve a record and check. Syntax of get API is being.


curl -XGET 'http://127.0.0.1:9200/docs_db/_doc/25060089?pretty'