Configuration params are reset after indexing

Hello,

I have function that fetch content and format it Algolia friendly and then index everything. It works well but, from time to times, on indexing the configuration settings defined in the Algolia dashboard are completely wiped out. It has consequences on the frontend using the search since it messes up with the searchable attributes and the facets.

After some research I realise that my function below might miss a step to have a basic settings config. In my understanding, the client.copySettings would do the job of getting the existing settings and applying it to the new index. But it turns out that I doesn’t sometimes (I haven’t been able to find the exact case where everything vanishes).

Do I need to setSettings my settings inside this indexing function (and potentially ignore new settings set only through the dashboard) or is there a way to ensure the settings are copied every time ?

const algoliasearch = require('algoliasearch')
const tempIndex = client.initIndex(`${process.env.ALGOLIA_INDEX_NAME}.tmp`)

function saveIndexes(entries) {
  return tempIndex
    .saveObjects(entries, {
      autoGenerateObjectIDIfNotExist: true,
    })
    .then((response) => {
      // Copy the main index settings, rules and synonyms to the temp index
      client.copySettings(
        process.env.ALGOLIA_INDEX_NAME,
        `${process.env.ALGOLIA_INDEX_NAME}.tmp`
      )
      client.copyRules(
        process.env.ALGOLIA_INDEX_NAME,
        `${process.env.ALGOLIA_INDEX_NAME}.tmp`
      )
      client.copySynonyms(
        process.env.ALGOLIA_INDEX_NAME,
        `${process.env.ALGOLIA_INDEX_NAME}.tmp`
      )

      // Enqueue a move index job to move the temp index to the main index
      client.moveIndex(
        `${process.env.ALGOLIA_INDEX_NAME}.tmp`,
        process.env.ALGOLIA_INDEX_NAME
      )

      console.log('saveIndexes', response)

      return response
    })
    .catch((e) => {
      console.log('Error saving objects', e)
      return e
    })
}

As a reference, here is the list of settings that I save through the dashboard :

{
  searchableAttributes: ['name', 'gamme', 'manufacturer', 'metier', 'search_terms', 'parent', 'grandparent'],
  attributesForFaceting: ['contentType'],
  keepDiacriticsOnCharacters: 'é'
}

Thanks in advance