Search Configuration
Learn the possibilities for configuring search in Emporix.
You can integrate the Emporix Commerce Engine with any index providers by leveraging the webhook events concept. Emporix CE recognizes all changes around a product item like the product itself, its price, category or availability related to the product. If any of the connected entities is modified, our platform prepares an index-item object which contains all the necessary data.
Enabling webhook service
Log in to the Management Dashboard and go to Administration -> Webhooks.
Choose the webhooks strategy that best suits your needs.
Extend the Index item webhook details and enable the Index item updated and the Index item deleted events.
Depending on the chosen webhook strategy, there are different ways to configure the endpoints for receiving notifications about events happening in the system. Configure your strategy to be able to process the events.
Search provider configuration
Commerce Engine allows you to configure your own search functionality. You can choose any provider that suits your needs. For demonstration purposes of how you can configure search through the webhooks functionality, we present examples of configuring Algolia and BatteryIncluded. These are the search engines that can be configured to work with Emporix CE and Svix.
Prerequisites
Before you start configuring a search engine in Emporix, ensure the following:
Enable the Index item updated and Index item deleted events are enabled in Management Dashboard, see Enabling webhook service.
Activate Algolia or BatteryIncluded account.
Initial steps
Log in to the Management Dashboard and go to Administration -> Webhooks.
Go to Svix by choosing the Open Svix Dashboard button.
To start the endpoint configuration, go to Endpoints.
Follow the steps for one of the providers: Algolia or BatteryIncluded.
Algolia Configuration
Creating and updating products
In Endpoints, choose Add Endpoint and fill in the fields with the following values:
Endpoint URL -
https://{ALGOLIA_APPLICATION_ID}.algolia.net/1/indexes
- provide your Algolia application IDDescription -
Algolia Create/Update
Message filtering - select only the
index-item.updated
event
Choose Create and check if your configuration was properly saved.
Go to the Advanced tab, provide the required custom headers and enable the transformation feature:
Key:
X-Algolia-API-Key
Value:YOUR_ALGOLIA_ADMIN_API_KEY
Key:
X-Algolia-Application-Id
Value:YOUR_ALGOLIA_APPLICATION_ID
Find the right values for your keys in your application settings (API Keys) in your Algolia account.
In the Transformations section, set the transformation feature to enabled.
In Edit transformation, start working on the Algolia mapping.
Since there are differences between the default mapping in Svix and Algolia requirements, we need to adjust the mapping to make it work properly.
The default mapping available in Svix is as follows:
/**
* @param webhook the webhook object
* @param webhook.method destination method. Allowed values: "POST", "PUT"
* @param webhook.url current destination address
* @param.webhook.eventType current webhook Event Type
* @param webhook.payload JSON payload
* @param.webhook.cancel whether to cancel dispatch of the given webhook
*/
function handler(webhook) {
// modify the webhook object...
// and return it
return webhook
}
According to Algolia API Reference, the request that should be sent is as follows:
curl "https://${APPLICATION_ID}.algolia.net/1/indexes/contacts/myID" \
-X PUT \
-H "X-Algolia-API-Key: ${API_KEY}" \
-H "X-Algolia-Application-Id: ${APPLICATION_ID}" \
-d '{
"name": "Betty Jane Mccamey",
"company": "Vita Foods Inc.",
"email": "betty@mccamey.com"
}'
To learn more about Algolia API, see Algolia API Reference.
In the Edit transformation section, change the code to create the right mapping: a. Change the http method:
/**
* @param webhook the webhook object
* @param webhook.method destination method. Allowed values: "POST", "PUT"
* @param webhook.url current destination address
* @param.webhook.eventType current webhook Event Type
* @param webhook.payload JSON payload
* @param.webhook.cancel whether to cancel dispatch of the given webhook
*/
function handler(webhook) {
webhook.method = "PUT";
return webhook
}
b. Modify the target URL:
/**
* @param webhook the webhook object
* @param webhook.method destination method. Allowed values: "POST", "PUT"
* @param webhook.url current destination address
* @param.webhook.eventType current webhook Event Type
* @param webhook.payload JSON payload
* @param.webhook.cancel whether to cancel dispatch of the given webhook
*/
function handler(webhook) {
var indexName = "emporix_" + webhook.payload.siteCode;
webhook.url = webhook.url + "/" + indexName + "/" + webhook.payload.id;
webhook.method = "PUT";
return webhook
}
c. Optional: Modify the message body. For example, you can add additional field like image based on media field:
/**
* @param webhook the webhook object
* @param webhook.method destination method. Allowed values: "POST", "PUT"
* @param webhook.url current destination address
* @param.webhook.eventType current webhook Event Type
* @param webhook.payload JSON payload
* @param.webhook.cancel whether to cancel dispatch of the given webhook
*/
function handler(webhook) {
if(webhook.payload.medias && webhook.payload.medias.length > 0) {
webhook.payload.image = webhook.payload.medias[0].url;
}
var indexName = "emporix_" + webhook.payload.siteCode;
webhook.url = webhook.url + "/" + indexName + "/" + webhook.payload.id;
webhook.method = "PUT";
return webhook
}
Choose Run test for the
index-item.updated
payload. As a result, you can see your transformed output.If the output is correct, save your changes.
To test the configuration, create a product in Management Dashboard and after a few minutes check if it appears in your index in the Algolia account. With this configuration, every time when a product is created or updated, the appropriate event is propagated to Svix, transformed and sent to Algolia.
Deleting products
In Endpoints, choose the Add Endpoint. Fill in the fields with the following values:
Endpoint URL -
https://{ALGOLIA_APPLICATION_ID}.algolia.net/1/indexes
- provide your Algolia application IDDescription -
Algolia Delete
Message filtering - select only the
index-item.deleted
event
Choose Create and check if your configuration was properly saved.
Go to the Advanced tab, provide the required custom headers and enable the transformation feature:
Key:
X-Algolia-API-Key
Value:YOUR_ALGOLIA_ADMIN_API_KEY
Key:
X-Algolia-Application-Id
Value:YOUR_ALGOLIA_APPLICATION_ID
Find the right values for your keys in your application settings (API Keys) in your Algolia account.
In the Transformations section, set the transformation feature to enabled.
According to Algolia API Reference, the request that should be sent is as follows:
curl -X DELETE \
-H "X-Algolia-API-Key: ${API_KEY}" \
-H "X-Algolia-Application-Id: ${APPLICATION_ID}" \
"https://${APPLICATION_ID}.algolia.net/1/indexes/contacts/myID"
To learn more about Algolia API, see Algolia API Reference.
In the Edit transformation section, change the code to create the right mapping: a. Change the http method:
/**
* @param webhook the webhook object
* @param webhook.method destination method. Allowed values: "POST", "PUT"
* @param webhook.url current destination address
* @param.webhook.eventType current webhook Event Type
* @param webhook.payload JSON payload
* @param.webhook.cancel whether to cancel dispatch of the given webhook
*/
function handler(webhook) {
webhook.method = "DELETE";
return webhook
}
b. Change the target URL:
/**
* @param webhook the webhook object
* @param webhook.method destination method. Allowed values: "POST", "PUT"
* @param webhook.url current destination address
* @param.webhook.eventType current webhook Event Type
* @param webhook.payload JSON payload
* @param.webhook.cancel whether to cancel dispatch of the given webhook
*/
function handler(webhook) {
var indexName = "emporix_" + webhook.payload.siteCode;
webhook.url = webhook.url + "/" + indexName + "/" + webhook.payload.id;
webhook.method = "DELETE";
return webhook
}
c. If the output is correct, save your changes.
To test the configuration, delete a product in Management Dashboard and after a few minutes check if it was deleted in your index in the Algolia account. With this configuration, every time when a product gets deleted, the appropriate event is propagated to Svix, transformed and then sent to Algolia.
BatteryIncluded Configuration
Creating and updating products
In Endpoints, choose Add Endpoint. Fill in the fields with the following values:
Endpoint URL -
https://api.batteryincluded.io/api/v1/collections/{BATTERY_INCLUDED_TENANT}/documents/import
Description -
BatteryIncluded Create/Update
Message filtering - select only the
index-item.updated
event
Replace the {BATTERY_INCLUDED_TENANT}
with the value from the URL address in the BatteryIncluded Portal.
For example, if the URL looks like this https://portal.batteryincluded.io/#/discover/customer.emporix
, the {BATTERY_INCLUDED_TENANT}
value is customer.emporix
.
Choose Create and check if your configuration was properly saved.
Go to the Advanced tab, provide the required custom headers:
Key:
X-BI-API-KEY
Value: Your private integration key
Find the right values for your keys in your connection settings in your BatteryIncluded account.
To test the configuration, create a product in Management Dashboard and after a few minutes check if it appears in your index in the BatteryIncluded account. With this configuration, every time when a product is created or updated, the appropriate event is propagated to Svix, transformed and then sent to BatteryIncluded.
Deleting products
In Endpoints, choose Add Endpoint. Fill in the fields with the following values:
Endpoint URL -
https://api.batteryincluded.io/api/v1/collections/{BATTERY_INCLUDED_TENANT}/documents/delete
Description -
BatteryIncluded Delete
Message filtering - select only the
index-item.deleted
event
Replace the {BATTERY_INCLUDED_TENANT}
with the value from the URL address in the BatteryIncluded Portal.
For example, if the URL looks like this https://portal.batteryincluded.io/#/discover/customer.emporix
, the {BATTERY_INCLUDED_TENANT}
value is customer.emporix
.
Choose Create and check if your configuration was properly saved.
Go to the Advanced tab, provide the required custom headers and enable the transformation feature:
Key:
X-BI-API-KEY
Value: Your private integration key
In the Transformations section, set the transformation feature to enabled.
In the Edit transformation section, change the code to create the right mapping. Modify the HTTP method:
/**
* @param webhook the webhook object
* @param webhook.method destination method. Allowed values: "POST", "PUT"
* @param webhook.url current destination address
* @param.webhook.eventType current webhook Event Type
* @param webhook.payload JSON payload
* @param.webhook.cancel whether to cancel dispatch of the given webhook
*/
function handler(webhook) {
// modify the webhook object...
// convert data
const playload = [webhook.payload.id]
webhook.method = "DELETE";
webhook.payload = playload
return webhook
}
If the output is correct, save your changes.
To test the configuration, delete a product in Management Dashboard and after a few minutes check if it was deleted in your index in the BatteryIncluded account. With this configuration, every time when a product is deleted, the appropriate event is propagated to Svix, transformed and then sent to BatteryIncluded.
Last updated
Was this helpful?