Partial update a document

Partial update a document #

Sometimes we may only need to update a portion fields of the document.

Examples #

Update the org.id field of the document news_001 in the collection my-collection:

PUT /my-collection/_doc/news_001/_update
{
  "sync":{
  	"replace":{
  	    "org": {
          "id": "infinilabs"
        }
    }
  }
}

The API returns as following result:

{"_id":"0,0", "_key":"news_001", "result":"updated"}

Pizza using the method of fetching a document, then merging partial updates and replacing it.

Request #

POST /<target>/_doc/<doc_id>/_update
{
  "sync":{
      <operation>: {<fields>}
    }
  "async":{
      <operation>: {<fields>}
    }
}

Pizza support both sync and async way to perform the updates, in order to update in realtime, you need to use sync here.

In asynchronous mode, the update process is considered complete once the request is committed to the WAL. Background tasks independently consume and process updates asynchronously, making it suitable for scenarios prioritizing update efficiency.

Path parameters #

  • <target>
    (Required, string) Name of the collection to target.
  • <doc_id>
    (Required, string) The unique identify of this document, support both _key or _id.

Request body #

  • <operation> The operation supported by partial updates: add, replace, remove, array_append.
  • <fields>
    (Required, string) The JSON format of the fields operation by partial updates.
Calendar March 9, 2024
Edit Edit this page