Synchronising Data
Batches of records can be sent to the indexing endpoint (indexing.ksearchnet.com/v2/batch) in order to add or update search data using the Indexing\BatchService.
Data is sent as a collection of Record objects (within a RecordIterator), which are transmitted as a single request. Note that if too many records are included in the same batch, the request will be rejected (either by the PHP-SDK validation or the API itself). The implementing application is responsible for creating and processing batches.
Data contained within a Record includes:
Field | Description |
---|---|
id | string Required Unique ID for the record in your indexes Examples: "1", "categoryid__12345" |
type | string Required Type of record, such as product or category. Custom values are allowed. Examples: "KLEVU_PRODUCT", "KLEVU_CATEGORY", "KLEVU_CMS", "ACME_RECORD" Note: the type of record will determine the degree of data validation performed by the API with, for example, KLEVU_PRODUCT records requiring attribute fields not present in other record types |
relations | array Array of relation defintions, such as categories and parent products. Example: [ 'categories' => [ 'values' => [ 'CATEGORY001', 'CATEGORY002', ], ], 'parentProduct' => [ 'values' => [ 'PARENT_PRODUCT_001', ], ], ] Note: no validation is performed on content of this field; refer to the API definition for details of structure and content |
attributes | array Array of record data, comprising core and custom attributes (if present) Example: [ 'name' => [ 'default' => 'Men Regular Mid Rise Dark Blue Jeans', 'fi-FI' => 'Miesten tavalliset Mid Rise tummansiniset farkut', ], 'sku' => 'SKU0001', 'image' => [ 'default' => [ 'url' => 'https://www.klevu.com/image.jpg', 'type' => 'default', 'height' => 100, 'width' => 100, ], ], ] Note: validation is performed for attribute name validity, but missing or invalid fields are not checked |
display | array Array of data which should be returned in search queries for use in storefront templates Example: [ 'default' => [ 'additionalProp1' => [], ], 'additionalProp1' => [], ] Note: validation is performed for attribute name validity |
IDs must be unique within your entire index, not just within a specific record type. For example, you could not send records with ID "1" for both "KLEVU_PRODUCT" and "KLEVU_CATEGORY".
If you are synchronising multiple record types which share IDs in your application, we recomend using a prefix for most or all records to ensure their uniqueness. For example product__1 / category__1
Note, data validity is not checked within the model itself, but is performed by the RecordValidator. This validator is not executed until you interact with Klevu APIs via the Indexing\BatchService, meaning invalid ids or attribute names, for example, will not be picked up at time of definition.
- Prior to transmitting data, the provided account credentials are validated as not empty and correctly formatted, throwing a ValidationException on failure.
- Prior to transmitting data, the Record data is validated, throwing a ValidationException on failure.
- Request exceptions, or responses identifying an invalid request throw aBadRequestException
- Client or Network exceptions, responses with unexpected status codes, or responses with a missing or invalid body content throw a BadResponseException
- Request headers and body are logged prior to send at DEBUG level
- Data used to generate the request bearer token is logged at DEBUG level
- Response headers, body, and execution time are logged on successful request send at DEBUG levelDeleting Records
More information and code samples can be found under Examples / How To > Data Indexing > Send Records for Indexing
Batches of record IDs can be sent to the indexing endpoint (indexing.ksearchnet.com/v2/batch/delete) in order to remove search data using the Indexing\Batch\DeleteService.
Data is provided as an array of strings corresponding to the ID value used when creating the record (above); type is not required as ID is unique across all records.
- Prior to transmitting data, the provided account credentials are validated as not empty and correctly formatted, throwing a ValidationException on failure.
- Prior to transmitting data, the Record IDs are validated, throwing a ValidationException on failure.
- Request exceptions, or responses identifying an invalid request throw aBadRequestException
- Client or Network exceptions, responses with unexpected status codes, or responses with a missing or invalid body content throw a BadResponseException
- Request headers and body are logged prior to send at DEBUG level
- Data used to generate the request bearer token is logged at DEBUG level
- Response headers, body, and execution time are logged on successful request send at DEBUG levelDeleting Records
More information and code samples can be found under Examples / How To > Data Indexing > Delete Records from Inde