Bulk Operations Indexing API
Bulk API helps to update perform CRUD operations on individual attributes of items.
Note
The term bulk operation implies the variety of operations which may be performed in a single request. For the limit of items, goto Bulk Operations API | Limits
This is achieved by sending a request to the indexing API to the URL:
Endpoint | Method | Header Key |
---|---|---|
api/v2/indexing/bulk-item-operations | POST | X-HawkSearch-ApiKey |
There are three operations which are part of bulk operations API described as follows.
Request
Name | Data Type | Required | Description |
---|---|---|---|
IndexName | String | yes | The name of the index to which the item(s) should be added. |
Operations | Array of objects | yes | The Operations variable holds the operation-specific objects. At-least one operation object is required |
> OperationType | String | yes | The name of the bulk operation to be performed. One of the four options are available: 1. index-items 2. delete-items 3. add-attribute-to-items 4. remove-attribute-from-items |
> Items | Array of item objects | yes if the operation type is not delete-items | The items on which the bulk operations are performed on Hawksearch. |
> > id | Alphanumeric | yes if the operation type is not delete-items | The unique id of the item |
> > {{property name}} | Alphanumeric | yes if the operation type is not delete-items | the attribute name for which the values need to be assigned |
> Ids | Array of Strings | yes if the operation type is delete-items | The unique_ids of the items which need to be removed from Hawksearch index. |
Methods
Add attribute to Items
Bulk operations API provides a significant advantage to update items individually. Any attribute may be updated for a collection of items at a single go. More than one value can be assigned to the itemβs attribute if necessary.
Remove Attributes from Items
This is the opposite of the add attribute method where attributes may be removed from the items.
Index Items
This method adds items to the Hawksearch index. This is similar to the index-items API call made to the endpoint api/v2/indexing/index-items. The index will not be set to be active until the set-current method is called, passing the name of the index. Each client engine can have multiple indexes, but only 1 current index at a time.
Delete Items
We can use this method to remove multiple items at the same time.
Limits
- Operations: there cannot be more than 125 operations per request
- Items: there cannot be 125 items per operation
- Total: the max limit is 125 operations x 125 items per operation = 15625 items per one bulk operations request
Example
Note that we may also combine these operations in a single request:
{
"IndexName": "myengine.20210101.123456",
"Operations": [{
"OperationType": "index-items",
"Items": [{
"aaa": ["bbb"],
"id": [
"1234"
],
"Sku": [
"987654"
],
"title": [
"Rain Jacket"
],
"price": [
"39.99"
],
"saleprice": [
"32.99"
],
"image": [
"http://www.mysite.com/images/Thumbnail/987654.jpg"
],
"url_detail": [
"http://www.mysite.com/jackets/mens/987654"
],
"brand": [
"Acme"
],
"color": [
"Orange"
]
},
{
"id": [
"987"
],
"Sku": [
"123456"
],
"title": [
"Down Jacket"
],
"price": [
"89.99"
],
"saleprice": [
"74.99"
],
"image": [
"http://www.mysite.com/images/Thumbnail/123456.jpg"
],
"brand": [
"Acme"
],
"color": [
"Black"
]
}
]
},
{
"OperationType": "delete-items",
"Ids": ["1234"]
},
{
"OperationType": "add-attribute-to-items",
"Items": [{
"id": ["Item_74500"],
"color-property": ["yellow", "red"]
}]
},
{
"OperationType": "remove-attribute-from-items",
"Items": [{
"id": ["Item_74500"],
"color-property": ["yellow"]
}]
}
]
}
Error Handling and Response for delete-items
Operation
delete-items
OperationThe delete-items
operation in the Bulk Operation Indexing API ensures consistent behavior when attempting to delete items, including scenarios where specified items do not exist in the index. The response is aligned with HTTP status codes and accurately reflects the result of the operation. Additionally, the response body will include a list of items that were not found and could not be deleted.
Response Scenarios for delete-items
Operation
delete-items
OperationScenario | HTTP Status Code | IsSuccess Value | Description |
---|---|---|---|
Single item exists | 200 OK | true | The specified item exists and is successfully deleted |
Single item does not exist | 400 Bad Request | false | The specified item does not exist in the index, deletion fails |
Multiple items, all exist | 200 OK | true | All specified items exist and are successfully deleted |
Multiple items, none exist | 400 Bad Request | false | None of the specified items exist in the index, deletion fails |
Multiple items, some exist, some do not | 400 Bad Request | false | At least one item does not exist in the index, partial deletion is not performed |
Updated 4 months ago