Add attribute for faceting in code instead of on dashboard

Hello, this was part of another thread but I figured since it’s a new question I should make a new thread.

Every time I reindex my data, I lose my attributes for faceting that I set in my Algolia Dashboard. I figure if I set the attributes in my code then maybe that wouldn’t happen anymore however, I’m not too sure where to place the code. Looking at the documentation, I see that they use index.settings({}) but I do not have that in my code. I tried here but that didn’t work. I am trying to add ApprovalFL to my attributesForFaceting:

var searchSong = instantsearch
            appId: "---",
            apiKey: "---",
            indexName: "Song",
            setSettings: ({ attributesForFaceting: ['ApprovalFL'] }),
            searchFunction: function (helper) {
                var query = searchArtist.helper.state.query;
                helper.state.index = "Song";
                //helper.state.hitsPerPage = 30;
                helper.state.facetFilters = ["ApprovalFL:true"];
                hitsPerPage: 30,

Here is my js for this specific index on a jsfiddle:

Thanks for the help so far!

OK for those using C# .NET it’s as simple as adding it to your Global.asax.cs for example for me:

var songIndexHelper = new IndexHelper<SongAlgoliaModel>(algoliaClient, "Song", "SongID");


1 Like