This topic describes how to update documents in a collection by using the HTTP API.
If the ID of a document to be updated does not exist, the update operation is invalid for the document.
If you update only some fields, the rest of the fields are set to
nullby default.
Prerequisites
A cluster is created. For more information, see Create a cluster.
An API key is obtained. For more information, see Manage API keys.
The SDK of the latest version is installed. For more information, see Install DashVector SDK.
Method and URL
PUT https://{Endpoint}/v1/collections/{CollectionName}/docsExample
You need to replace YOUR_API_KEY with your API key and YOUR_CLUSTER_ENDPOINT with the endpoint of your cluster in the sample code for the code to run properly.
You need to create a collection named
quickstartin advance. For more information, see the "Example" section of the Create a collection topic.
Update a document
curl -XPUT \
-H 'dashvector-auth-token: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"docs": [{"id": "1", "vector": [0.1, 0.2, 0.3, 0.4]}]
}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/docs
# example output:
# {"request_id":"3fc2acfa-48cb-4924-8ef7-f94388ecb07d","code":0,"message":"Success"}Update a document with fields
curl -XPUT \
-H 'dashvector-auth-token: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"docs": [
{
"id": "2",
"vector": [0.2, 0.3, 0.4, 0.5],
"fields":
{
"age": 70,
"name": "zhangshan",
"anykey1": "str-value",
"anykey2": 1,
"anykey3": true,
"anykey4": 3.1415926
}
}
]
}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/docs
# example output:
# {"request_id":"4abd0c5e-78a6-488b-976f-16f0d2e628c5","code":0,"message":"Success"}Update multiple documents at a time
curl -XPUT \
-H 'dashvector-auth-token: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"docs": [
{"id": "3", "vector": [0.3, 0.4, 0.5, 0.6]},
{"id": "4", "vector": [0.4, 0.5, 0.6, 0.7], "fields": {"age": 20, "name": "zhangsan"}},
{"id": "5", "vector": [0.5, 0.6, 0.7, 0.8], "fields": {"anykey": "anyvalue"}}
]
}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/docs
# example output:
# {"request_id":"19215409-ea66-4db9-8764-26ce2eb5bb99","code":0,"message":""}Update a document containing a sparse vector
curl -XPUT \
-H 'dashvector-auth-token: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"docs": [
{"id": "6", "vector": [0.1, 0.2, 0.3, 0.4], "sparse_vector":{"1":0.4, "10000":0.6, "222222":0.8}}
]
}' https://YOUR_CLUSTER_ENDPOINT/v1/collections/quickstart/docs
# example output:
# {"request_id":"4fefe855-ae39-48b3-9aa8-f45a77a3cd29","code":0,"message":"Success"}Request parameters
Parameter | Location | Type | Required | Description |
{Endpoint} | path | str | Yes | The endpoint of the cluster. You can view the endpoint on the cluster details page in the console. |
{CollectionName} | path | str | Yes | The name of the collection. |
dashvector-auth-token | header | str | Yes | The API key. |
docs | body | array | Yes | The list of documents to be updated. |
partition | body | str | No | The name of the partition. |
Response parameters
Parameter | Type | Description | Example |
code | int | The returned status code. For more information, see Status codes. | 0 |
message | str | The returned message. | success |
request_id | str | The unique ID of the request. | 19215409-ea66-4db9-8764-26ce2eb5bb99 |