Algolia
The Enterspeed Algolia integration uses the destinations field to send data from views directly to a configured Algolia index. This means that you can decide on the schema level which views you want to send to Algolia.
You will only have to set the destination field on the entity schema you want to send to Algolia. All schema references are automatically resolved so you don't have to set it on all referenced schemas.
It's possible to configure multiple Algolia destinations if you need to push different types of data to different Algolia indexes.
Configuration
In order to setup the Algolia configuration you need the following:
Setting | Description |
---|---|
Algolia Index Name | The name of the Algolia index you want to integrate to |
Algolia Application ID | The unique application identifier used to identify you when working with Algolia's API |
Algolia API Key | The API key needs addObject and deleteObject rights for the index you want to integrate to |
Enterspeed Environment Client API Key | The API key for an Enterspeed Environment client. This is used to fetch the view that will be inserted into Algolia |
Options
Table of available options, that you can optionally specify, if needed for your use case.
Setting | Description |
---|---|
objectId | By default Enterspeed uses view id as the value for object id in Algolia. You can override default object id by providing value for this option. |
indexName | Option to override what index must be used for current view. By default IndexName of Algolia configuration is used. |
partialUpdate | A boolean indicating if the update of the Algolia record should be a partial update. See Algolia documentation. Default value: false |
createIfNotExists | A boolean indicating if the partial update should create a record in Algolia if it does not already exists. Only used if partialUpdate is set to true .Default value: false |
skipDelete | A boolean indicating if a deleted view should delete the record in Algolia. Typically set to false for partialUpdate if the schema is not working on the "master" object.Default value: false |
Algolia does not support partial deletes. This means that if you are using partial updates and you want to clear the attributes from the partial update, you should not delete the source entity that triggers the partial update in Enterspeed.
Instead you should update the source entity and set the properties to default values, like null, an empty string, an empty array and so on.
Example of usage
- JavaScript
- JSON
/** @type {Enterspeed.FullSchema} */
export default {
triggers: function(context) {
context.triggers('geodata', ['city']);
},
actions: function (sourceEntity, context) {
context.destination('algolia').options({
objectId: `city-${sourceEntity.originId}`
partialUpdate: false
});
},
properties: function ({url, properties: p}, context) {
return {
url: url,
name: p.name
}
}
}
{
"triggers": {
"geodata": ["city"]
},
"destinations": [
{
"alias": "algolia",
"options": {
"objectId": "city-{originId}"
}
}
],
"properties": {
"url": "{url}",
"name": "{p.name}"
}
}
Algolia specific properties
_geoloc
_geoloc
is a special property in Algolia used for doing geo-searching. See Algolia documentation
As stated in the Algolia documentation, the lat
and lng
properties must be numeric values. This means that you will need to make sure that your Enterspeed schema is mapping these properties as numeric values and not as strings.
- JavaScript
- JSON
/** @type {Enterspeed.FullSchema} */
export default {
triggers: function(context) {
context.triggers('geodata', ['city']);
},
actions: function (sourceEntity, context) {
context.destination('algolia').options({
objectId: `city-${sourceEntity.originId}`
});
},
properties: function ({url, properties: p}, context) {
return {
url: url,
name: p.name,
_geoloc: {
lat: p.lat,
lng: p.lng,
}
}
}
}
{
"triggers": {
"geodata": ["city"]
},
"destinations": [
{
"alias": "algolia",
"options": {
"objectId": "city-{originId}"
}
}
],
"properties": {
"url": "{url}",
"name": "{p.name}",
"_geoloc": {
"type": "object",
"properties": {
"lat": {
"type": "number",
"value": "40.639751",
"precision": 6
},
"lng": {
"type": "number",
"value": "-73.778925",
"precision": 6
}
}
}
}
}