Defining indexable properties
When you create a search index, a corresponding webhook is set up using the configuration you specified in the search index wizard. When a content item of one of your specified content types is published, created or updated, the webhook will be triggered and a request will be sent to the search API to update your index.
The webhook is all set up for you, so the only changes you should need to make are to the custom payload. The custom payload is used to define the body of the request that gets sent to the search API, which generates the record that is created in your search index. You can use the custom payload to include the properties that you need to implement your search functionality.
Amplience search is powered by Algolia and uses JSON to model records. To find out more about how search records are structured, see the Algolia guide to formatting and structuring your data.
On this page we'll explain how you can update the custom payload to include all the properties that you need to facilitate search, display, filtering or relevance. You can also transform data to achieve the results you need, for example converting a date into a UNIX timestamp to make it sortable.
The default custom payloadLink copied!
The custom payload is specified in handlebars format and is used to generate JSON output.
When you first create an index using the wizard, the custom payload will look something like the following:
This will include just the properties of the _meta
section of the content type. In some cases this information will be all you need to include in your search index and you will be able to use the deliveryKey
or deliveryID
to retrieve the full content item.
An example payload body generated from a content item of the blog content type and the default custom payload is shown below. In this example the content item does not have a delivery key and you would use the deliveryID to retrieve the full item.
An example search record created using the default payload shown in the image below.
Updating the custom payloadLink copied!
In most cases you will need to update your custom payload to include any additional properties that you require to facilitate search.
Your payload should include all the fields used in your search configuration (searchableAttributes, attributesForFaceting and customRanking) together with any other fields you need to use for display purposes to build your front end. For the blog post content type this might include the image URL.
To view the custom payload, you need to edit the indexing webhook for your search index. Choose "Search indexes" from the "Development" menu, view your search index and then open the Webhooks tab.
Scroll to the "payload" section in "Settings" to view or edit the custom payload.
Output all propertiesLink copied!
For testing purposes, or if your content type schema contains only a few properties, you can create search records from all the properties in a content type. Update the custom payload to {{{JSONstringify this}}}
as shown below:
Algolia recommends that, for performance reasons, the maximum size of a record should not exceed 5KB. We recommend that you refine the the custom payload to optimize the size of the record created in Algolia by including only those properties that you want to be used for your search.
Optimizing your propertiesLink copied!
In the custom payload for the blog post content type, shown in the example below, we might want to index the title, description, author names, tags, date, readTime and the content itself so that all these fields are available to your search. In this example we are using some of our supported handlebars helpers to transform the data, and to pick out the parts we need.
Leaving the opening and closing expressions for the withDeliveryContentItem
helper in place, edit the default custom payload as follows:
An example of a webhook with an updated custom payload is shown in the image below.
With the updated custom payload, when a blog content item is published, only properties included in the custom payload (together with the objectID) are included in the index.
After updating your custom payload, if you have changed the names of any attributes, or added new ones, you may need to update your search settings. If you aren't using Dynamic Content search, then see the Algolia dashboard for these settings.
For more detail on refining your search index, see our guide to refining your search index.