Modify autocomplete data sources

Hi, we are using this code to customize our autocomplete suggestion search before and it was working

algolia.registerHook('beforeAutocompleteSources', function(sources, algoliaClient, algoliaBundle) {

    // Parsing the different autocomplete source to find the suggestions one
    for (var i = 0; i < sources.length; i++) {
        if (sources[i].name === 'suggestions') {
            // Modify suggestions source
            // Set new index containing the Algolia Query Suggestions
            // Get index name from the system config
            if (typeof algoliaConfig.autocomplete.querySuggestions != 'undefined') {
                var index = algoliaClient.initIndex(algoliaConfig.autocomplete.querySuggestions.indexName),
                    suggestionsSource = algoliaBundle.$.fn.autocomplete.sources.hits(index, {
                        hitsPerPage: algoliaConfig.autocomplete.nbOfQueriesSuggestions,
                        restrictSearchableAttributes: ['query']

                console.log('index',  algoliaBundle);
                // Replacing the data for the suggestions source
                sources[i] = {
                    source: suggestionsSource,
                    displayKey: 'query',
                    name: 'suggestions',
                    templates: {
                        header: '<div class="category suggestions-heading">Suggested searches:</div>',
                        suggestion: function(hit) {
                            hit.url = algoliaConfig.baseUrl + '/catalogsearch/result/?q=' + hit.query;

                            return algoliaConfig.autocomplete.templates.suggestions.render(hit);


    return sources;

but after upgrading to algoliasearch-magento-2 to 3.8.1 we encounter some error

The error causing this is because of this


there is no autocomplete when getting this algoliaBundle.$.fn via console log

unlike before the upgrade

I’ve been checking also this documentation but its not working on my end and I think its not for the latest version?

Any suggestion on how to modify the autocomplete data source for the latest algolia version for magento 2?

Thanks in advance.

@chris8 welcome to the community!

I’ve reached out to our Magento team for some assistance with this issue. It is late Friday, so we may not hear something back until early next week.

@chris8 the Magento team got back to me and let me know the following:

  1. We have a pending marketplace update that should be released on Oct 27th which contains some improvements/fixes
  2. Or, to hold you over until the release, you can manually patch to v3.9.0 (from v.3.8.1) by using the following:

PR: Release/3.9.0 by mohitalgolia · Pull Request #1258 · algolia/algoliasearch-magento-2 · GitHub

@michael.king Thanks for the update, will ask our team to try this patch update and hoping it will solve the issue.

@chris8 v3.9.0 has been officially released: Release Notes