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. |
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 |
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
}
}
}
}
}