> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Set settings

> Change an index's settings.

export const Legacy = ({title, href}) => {
  return <Note>

    This page documents an earlier version of the API client.
    For the latest version, see <a href={href}>{title}</a>.

    </Note>;
};

<Legacy title="Update index settings" href="/doc/libraries/sdk/methods/search/set-settings" />

**Required ACL:** `editSettings`

**Only specified settings are overridden.**
Unspecified settings are left unchanged.
Specifying `null` for a setting resets it to its default value.
For a list of available settings, see [Index settings](/doc/api-reference/settings-api-parameters).

For best performance, change the settings before you add records to your index.

## Examples

### Set settings

<CodeGroup>
  ```cs C# theme={"system"}
  IndexSettings settings = new IndexSettings
  {
    SearchableAttributes = new List<string> { "name", "address" },
    CustomRanking = new List<string> { "desc(followers)" }
  };

  index.SetSettings(settings);

  // Asynchronous
  await index.SetSettingsAsync(settings);
  ```

  ```go Go theme={"system"}
  settings := search.Settings{
  	SearchableAttributes: opt.SearchableAttributes("name", "address"),
    CustomRanking: opt.CustomRanking("desc(followers)"),
  }
  res, err := index.SetSettings(settings)
  ```

  ```java Java theme={"system"}
  index.setSettings(
    new IndexSettings()
      .setSearchableAttributes(Arrays.asList("name", "address"))
      .setCustomRanking(Collections.singletonList("desc(followers)"))
  );

  // Asynchronous
  index.setSettingsAsync(
    new IndexSettings()
      .setCustomRanking(Collections.singletonList("desc(followers)"))
  );
  ```

  ```js JavaScript theme={"system"}
  index.setSettings({
    'searchableAttributes': ['name', 'address'],
    'customRanking': ['desc(followers)']
  }).then(() => {
    // done
  });
  ```

  ```kotlin Kotlin theme={"system"}
  val settings = settings {
      searchableAttributes {
          +"name"
          +"address"
      }
      customRanking {
          +Desc("followers")
      }
  }

  index.setSettings(settings)
  ```

  ```php PHP theme={"system"}
  $index->setSettings(
    [
      'searchableAttributes' => ['name', 'address']
      'customRanking' => ['desc(followers)']
    ]
  );
  ```

  ```python Python theme={"system"}
  index.set_settings({
    "searchableAttributes": ["name", "address"],
    "customRanking": ["desc(followers)"]
  })
  ```

  ```ruby Ruby theme={"system"}
  index.set_settings({
    searchableAttributes: ['name', 'address'],
    customRanking: ['desc(followers)']
  })
  ```

  ```scala Scala theme={"system"}
  client.execute {
    setSettings of "YourIndexName" `with` IndexSettings(
      searchableAttributes = Some(
        Seq(
          SearchableAttributes.attributes("name"),
          SearchableAttributes.attributes("address")
        )
      ),
      customRanking = Some(Seq(CustomRanking.desc("followers")))
    )
  }
  ```

  ```swift Swift theme={"system"}
  let settings = Settings()
    .set(\.searchableAttributes, to: [.default(["name", "address"])])
    .set(\.customRanking, to: [.desc("followers")])

  index.setSettings(settings) { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

### Set settings and forward to replicas

<CodeGroup>
  ```cs C# theme={"system"}
  IndexSettings settings = new IndexSettings
  {
    SearchableAttributes = new List<string> { "name", "adress" },
    CustomRanking = new List<string> { "desc(followers)" }
  };

  index.SetSettings(settings, forwardToReplicas: true);

  // Asynchronous
  await index.SetSettingsAsync(settings, forwardToReplicas: true);
  ```

  ```go Go theme={"system"}
  settings := search.Settings{
    SearchableAttributes: opt.SearchableAttributes("name", "address"),
    CustomRanking: opt.CustomRanking("desc(followers)"),
  }
  res, err := index.SetSettings(settings, opt.ForwardToReplicas(true))
  ```

  ```java Java theme={"system"}
  index.setSettings(
    new IndexSettings()
      .setSearchableAttributes(Arrays.asList("name", "address"))
      .setCustomRanking(Collections.singletonList("desc(followers)")),
      forwardToReplicas: true
  );

  // Asynchronous
  index.setSettingsAsync(
    new IndexSettings()
      .setSearchableAttributes(Arrays.asList("name", "address"))
      .setCustomRanking(Collections.singletonList("desc(followers)")),
      forwardToReplicas: true
  );
  ```

  ```js JavaScript theme={"system"}
   index.setSettings({
     'searchableAttributes': ['name', 'address'],
     'customRanking': ['desc(followers)']
   }, {
     forwardToReplicas: true
   }).then(() => {
     // done
   });
  ```

  ```kotlin Kotlin theme={"system"}
  val settings = settings {
      searchableAttributes {
          +"name"
          +"address"
      }
      customRanking {
          +Desc("followers")
      }
  }

  index.setSettings(settings, forwardToReplicas = true)
  ```

  ```php PHP theme={"system"}
  $forwardToReplicas = true;

  $index->setSettings(
    [
      'searchableAttributes' => ['name', 'address'],
      'customRanking' => ['desc(followers)'],
    ],
    [
      'forwardToReplicas' => $forwardToReplicas
    ]
  );
  ```

  ```python Python theme={"system"}
  index.set_settings({
      "searchableAttributes": ["name", "address"],
      "customRanking": ["desc(followers)"],
  }, {
      "forwardToReplicas": True
  })
  ```

  ```ruby Ruby theme={"system"}
  index.set_settings({
    searchableAttributes: ['name', 'address'], 
    customRanking: ['desc(followers)']
  }, { 
    forwardToReplicas: true
  })
  ```

  ```scala Scala theme={"system"}
  client.execute {
    setSettings of "YourIndexName" `with` IndexSettings(
      searchableAttributes = Some(
        Seq(
          SearchableAttributes.attributes("name"),
          SearchableAttributes.attributes("address")
        )
      ),
      customRanking = Some(Seq(CustomRanking.desc("followers"))),
      forwardToReplicas = Some(forwardToReplicas.`true`)
    )
  }
  ```

  ```swift Swift theme={"system"}
  let settings = Settings()
    .set(\.searchableAttributes, to: [.default(["name", "address"])])
    .set(\.customRanking, to: [.desc("followers")])

  index.setSettings(settings, forwardToReplicas: true) { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

## Parameters

<ParamField body="settings" type="object" required>
  A mapping of [settings parameters](/doc/api-reference/settings-api-parameters)
  you can use on an index.
</ParamField>

<ParamField body="forwardToReplicas" type="boolean" default={false}>
  Whether to forward the same settings to the replica indices.

  **Note:** when forwarding settings, please make sure your replicas already exist. It's impossible to forward settings *and* create your replicas at the same time.
</ParamField>

<ParamField body="requestOptions" type="object">
  A mapping of additional request options,
  such as timeouts or headers.
</ParamField>

## Response

<ResponseField name="taskID" type="integer">
  The task ID used with the [`waitTask`](/doc/libraries/sdk/v1/methods/wait-task) method.
</ResponseField>

<ResponseField name="updatedAt" type="string">
  Date at which the indexing job has been created.
</ResponseField>

### Response as JSON

This section shows the JSON response returned by the API.
Each API client wraps this response in language-specific objects, so the structure may vary.
To view the response, use the `getLogs` method.
Don't rely on the order of properties—JSON objects don't preserve key order.

```jsonc JSON icon=braces theme={"system"}
{
  "updatedAt":"2013-01-18T15:33:13.556Z",
  "taskID": 678
}
```
