Updating Products in Marqo
This guide shows you how to update existing product documents in your Marqo ecommerce search index using partial updates. Learn how to efficiently modify specific fields without needing to resend the entire product document.
Prerequisites
- A Marqo Cloud account (sign up here)
- Your Marqo API key (find your API key guide)
- An existing ecommerce index with products (add products guide)
Partial Update Documents
Update existing product documents by making a PATCH /documents
request. This endpoint allows you to modify specific fields without affecting other product data.
{
"documents": [
{
"_id": "PROD-001",
"price": 179.99,
"product_description": "Updated description with new features"
}
]
}
Key Differences from Add Products
- Method:
PATCH
instead ofPOST
- Required Fields: Only
_id
is required - all other fields are optional - Behavior: Updates only the fields you specify, leaving other fields unchanged
- Body Structure: Identical to Add Products but with optional fields
For complete field documentation, see the Add Products guide.
Update Examples
Price Update
Update just the price of a product:
{
"_id": "PROD-001",
"price": 149.99
}
Description and Collections Update
Update product description and add it to new collections:
{
"_id": "PROD-002",
"product_description": "Enhanced with new noise-cancellation technology",
"collections": ["electronics", "audio", "premium", "new-features"]
}
Stock and Custom Fields Update
Update custom fields like stock quantity and availability:
{
"_id": "PROD-003",
"stock_quantity": 25,
"is_available": true,
"last_updated": "2024-01-15T10:30:00Z"
}
Variant Information Update
Update variant-specific information:
{
"_id": "VARIANT-001",
"variant_name": "Premium Wireless Headphones - Matte Black - Limited Edition",
"price": 229.99,
"collections": ["electronics", "audio", "limited-edition"]
}
Updating Products in Your Index
# Single product update
curl -X PATCH 'https://api.marqo.ai/api/v2/indexes/your-ecommerce-index/documents' \
-H "x-api-key: your_api_key_here" \
-H 'Content-type: application/json' \
-d '{
"documents": [
{
"_id": "PROD-001",
"price": 179.99,
"product_description": "Updated with latest features and improvements"
}
]
}'
# Bulk update example
curl -X PATCH 'https://api.marqo.ai/api/v2/indexes/your-ecommerce-index/documents' \
-H "x-api-key: your_api_key_here" \
-H 'Content-type: application/json' \
-d '{
"documents": [
{
"_id": "PROD-001",
"price": 179.99
},
{
"_id": "PROD-002",
"stock_quantity": 50,
"is_available": true
},
{
"_id": "PROD-003",
"collections": ["electronics", "bestsellers"]
}
]
}'
Response
The response structure is identical to the Add Products endpoint. A status code of 200
indicates successful processing.
Field Name | Type | Description |
---|---|---|
errors |
Boolean | Indicates whether any errors occurred during the processing of the batch request. |
items |
Array | An array of objects, each representing the processing status of an individual document update. |
processingTimeMs |
Integer | The time taken to process the batch request, in milliseconds. |
index_name |
String | The name of the index where documents were updated. |
Response Status Codes
Status Code | Description |
---|---|
200 |
The document was successfully updated. |
400 |
Bad request. Invalid input or document ID not found. |
404 |
Document with the specified _id does not exist. |
429 |
Too many requests. Please try again later. |
500 |
Internal error. |
Best Practices
Efficient Updates
- Update only changed fields - Don't include fields that haven't changed
- Batch updates - Group multiple updates into single requests for better performance
- Use specific IDs - Ensure
_id
values match existing documents exactly
Common Update Patterns
- Price updates - For sales, promotions, or inventory changes
- Stock management - Update availability and quantity fields
- Content improvements - Enhance descriptions and add new collections
- Seasonal changes - Update collections for holidays or seasons
Error Handling
Check the response status and handle errors appropriately:
# Example error response handling
{
"errors": true,
"items": [
{"_id": "PROD-001", "status": 200, "message": "Document updated successfully"},
{"_id": "PROD-999", "status": 404, "message": "Document not found"}
]
}
Monitor the errors
field and individual item statuses to identify any failed updates.
Performance Tips
- Batch size - Update 50-100 products per request for optimal performance
- Frequency - Avoid updating the same products too frequently
- Field types - Remember that only certain field types can be vectorized (see Add Products guide)
Common Update Scenarios
Inventory Management
Update stock levels and availability:
{
"_id": "PROD-001",
"stock_quantity": 15,
"is_available": true,
"last_restocked": "2024-01-15"
}
Pricing Changes
Update prices for sales or promotions:
{
"_id": "PROD-002",
"price": 99.99,
"sale_price": 79.99,
"on_sale": true
}
Content Enhancement
Improve product information:
{
"_id": "PROD-003",
"product_description": "Enhanced description with detailed specifications and benefits",
"features": ["bluetooth-5.0", "noise-cancellation", "30hr-battery"],
"collections": ["electronics", "audio", "featured"]
}