Optimizing your records

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. You can use the custom payload to include only those properties that you need to implement your search functionality, as well as optimizing the size of each record.

On this page we'll explain how you can use update the custom payload to refine the properties that are included in the records in your index.

The default custom payload

When you first create an index using the wizard, the custom payload will look something like the following:

{{#withDeliveryContentItem contentItemId=payload.rootContentItem.id account="ampproduct" stagingEnvironment="kuifkfmrgfsv1qjsmei8dbbnq.staging.bigcontent.io" snapshotId=payload.id}}
{{{JSONstringify this}}}
{{/withDeliveryContentItem}}

This will include all of the properties of the content type in the webhook request, so all of these properties will be added to your search index.

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

If you are using Content Delivery 2 and want to retrieve a content item using its delivery key, then you can also include the delivery key in the custom payload.

Updating the custom payload

To view the webhook, click the webhook name or choose 'Open indexing webhook" from its menu. Scroll to the "payload" section in "Settings" to view or edit the custom payload.

A webhook is created for each content type associated with an index
A webhook is created for each content type associated with an index

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. For the blog post content, you might choose to include just an excerpt to prevent your record from becoming too large.

Replace "myAccountId" with your Amplience account name and "vseURL" with the virtual staging domain from your hub.


{
  {{#withDeliveryContentItem contentItemId=payload.rootContentItem.id account="myAccountId" stagingEnvironment="myVseUrl" snapshotId=payload.id}}
  "title": "{{{title}}}",
  "description": "{{{description}}}",
  "deliveryKey": "{{{_meta.deliveryKey}}}",
  "authors": [
  {{#each authors}}{{#if @index}},{{/if}}
    {
      "name":"{{{name}}}"
    }
  {{/each}}
  ],
  "tags": {{{JSONstringify tags}}},
  "date": "{{{this.date}}}",
  "readTime": {{{readTime}}},
  "dateAsTimeStamp": {{{moment date format="X"}}}, 
  "content": [
  {{#each content}}
    {{#if text}}
        {{#if @index}},{{/if}}
        {{{JSONstringify text}}}
    {{/if}}
  {{/each}}
  ],
  "imagePath":"{{{image.image.endpoint}}}/{{{image.image.name}}}"
  {{/withDeliveryContentItem}}
}

An example of a webhook with an updated custom payload is shown in the image below.

Updating the custom payload to include only those properties that you want to include in your index
Updating the custom payload to include only those properties that you want to include in your index

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.

Only those properties included in the custom payload are added to the index
Only those properties included in the custom payload are added to 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.

Search index overview

Search index configuration

A guide to refining your search index.

results matching ""

    No results matching ""