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:

EndpointMethodHeader Key
api/v2/indexing/bulk-item-operationsPOSTX-HawkSearch-ApiKey

There are three operations which are part of bulk operations API described as follows.

Request

NameData TypeRequiredDescription
IndexNameStringyesThe name of the index to which the item(s) should be added.
OperationsArray of objectsyesThe Operations variable holds the operation-specific objects. At-least one operation object is required
> OperationTypeStringyesThe 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
> ItemsArray of item objectsyes if the operation type is not delete-itemsThe items on which the bulk operations are performed on Hawksearch.
> > idAlphanumericyes if the operation type is not delete-itemsThe unique id of the item
> > {{property name}}Alphanumericyes if the operation type is not delete-itemsthe attribute name for which the values need to be assigned
> IdsArray of Stringsyes if the operation type is delete-itemsThe 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

  1. Operations: there cannot be more than 125 operations per request
  2. Items: there cannot be 125 items per operation
  3. 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

The 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

ScenarioHTTP Status CodeIsSuccess ValueDescription
Single item exists200 OKtrueThe specified item exists and is successfully deleted
Single item does not exist400 Bad RequestfalseThe specified item does not exist in the index, deletion fails
Multiple items, all exist200 OKtrueAll specified items exist and are successfully deleted
Multiple items, none exist400 Bad RequestfalseNone of the specified items exist in the index, deletion fails
Multiple items, some exist, some do not400 Bad RequestfalseAt least one item does not exist in the index, partial deletion is not performed