Bulk Operations API
Bulk API helps to update perform CRUD operations on individual attributes of items.
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 | Datatype | 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:
|
>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"]
}]
}
]
}