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

# attributesForFaceting

> List of attributes to use for faceting and filtering

\<ul><li>**Type:** `list<string>`</li>
      \<li>**Default:** `[]`(no facets)</li>
      
      
      \<li>**Scope:** [`settings`](https://www.algolia.com/doc/api-reference/api-parameters)</li></ul>Faceting lets users narrow down search results by selecting attribute values, such as author, genre, or brand.
To use an attribute for faceting or filtering, declare it in `attributesForFaceting`.To learn more, see [Declare attributes for faceting](https://www.algolia.com/doc/guides/managing-results/refine-results/faceting/how-to/declaring-attributes-for-faceting.md).> [!NOTE]
>
> There's no hard limit on the number of attributes you can include,
> but adding too many can slow down [`getSettings`](https://www.algolia.com/doc/rest-api/search/get-settings) operations
> and degrade performance in the Algolia dashboard.## Usage- Attribute names are case-sensitive
- Declaring an attribute here enables:
  * **Faceting**—use attributes inside [facets](https://www.algolia.com/doc/guides/managing-results/refine-results/faceting)
  * **Filtering**—use attributes inside [`filters`](https://www.algolia.com/doc/api-reference/api-parameters/filters), [`facetFilters`](https://www.algolia.com/doc/api-reference/api-parameters/facetFilters), and [`optionalFilters`](https://www.algolia.com/doc/api-reference/api-parameters/optionalFilters)
- You can use [nested attributes](https://www.algolia.com/doc/guides/managing-results/refine-results/faceting) for faceting, such as `authors.mainAuthor`. Refer to the facet by its full path, `authors.mainAuthor`.
- Declaring a parent object covers every nested attribute below it. Declaring `authors` makes `authors.mainAuthor` and its siblings available for faceting, each requested by its own full path. Requesting the parent path alone doesn't return any facet.
- Avoid colons (`:`) in facet attribute names faceting as the `filters` syntax uses colons as delimiters.## ModifiersUse *modifiers* to change the behavior of faceted attributes.**filterOnly**Marks an attribute as available only for filtering—not faceting.
This is useful when you want to filter by an attribute but don't need to display its facet values.
It also reduces index size and improves performance.> [!NOTE]
>
> You can't use `filterOnly` and `searchable` together.**searchable**Makes a facet searchable—users can type to [find facet values](https://www.algolia.com/doc/guides/managing-results/refine-results/faceting#search-for-facet-values).You can combine this modifier with `afterDistinct`: `afterDistinct(searchable(attribute))`.> [!NOTE]
>
> You can't use `filterOnly` and `searchable` together.**afterDistinct**Ensures facet counts reflect only unique records when using the [`distinct`](https://www.algolia.com/doc/api-reference/api-parameters/distinct) setting.
Use this when deduplicating records and you want accurate facet counts.- Only use `afterDistinct` on attributes shared by all records with the same distinct key.
- If [`facetingAfterDistinct`](https://www.algolia.com/doc/api-reference/api-parameters/facetingAfterDistinct) is also set to `true`, it takes precedence and applies to all the query's facets.You can combine this modifier with `searchable`: `afterDistinct(searchable(attribute))`.## ExampleThe following example:* Defines some attributes as facets: `author`, `edition`, `category`, and `publisher`
* Sets the `isbn` attribute as only usable for filtering
* Allows the `edition` and `publisher` facet values to be searchable> [accordion] Current API clients
>
> ```cs C# theme={"system"}
> var response = await client.SetSettingsAsync(
>   "INDEX_NAME",
>   new IndexSettings
>   {
>     AttributesForFaceting = new List<string>
>     {
>       "author",
>       "filterOnly(isbn)",
>       "searchable(edition)",
>       "afterDistinct(category)",
>       "afterDistinct(searchable(publisher))",
>     },
>   }
> );
> ```
>
> ```dart Dart theme={"system"}
> final response = await client.setSettings(
>   indexName: "INDEX_NAME",
>   indexSettings: IndexSettings(
>     attributesForFaceting: [
>       "author",
>       "filterOnly(isbn)",
>       "searchable(edition)",
>       "afterDistinct(category)",
>       "afterDistinct(searchable(publisher))",
>     ],
>   ),
> );
> ```
>
> ```go Go theme={"system"}
> response, err := client.SetSettings(client.NewApiSetSettingsRequest(
>   "INDEX_NAME",
>   search.NewEmptyIndexSettings().SetAttributesForFaceting(
>     []string{"author", "filterOnly(isbn)", "searchable(edition)", "afterDistinct(category)", "afterDistinct(searchable(publisher))"})))
> if err != nil {
>   // handle the eventual error
>   panic(err)
> }
> ```
>
> ```java Java theme={"system"}
> UpdatedAtResponse response = client.setSettings(
>   "INDEX_NAME",
>   new IndexSettings().setAttributesForFaceting(
>     Arrays.asList(
>       "author",
>       "filterOnly(isbn)",
>       "searchable(edition)",
>       "afterDistinct(category)",
>       "afterDistinct(searchable(publisher))"
>     )
>   )
> );
> ```
>
> ```js JavaScript theme={"system"}
> const response = await client.setSettings({
>   indexName: 'theIndexName',
>   indexSettings: {
>     attributesForFaceting: [
>       'author',
>       'filterOnly(isbn)',
>       'searchable(edition)',
>       'afterDistinct(category)',
>       'afterDistinct(searchable(publisher))',
>     ],
>   },
> });
> ```
>
> ```kotlin Kotlin theme={"system"}
> var response =
>   client.setSettings(
>     indexName = "INDEX_NAME",
>     indexSettings =
>       IndexSettings(
>         attributesForFaceting =
>           listOf(
>             "author",
>             "filterOnly(isbn)",
>             "searchable(edition)",
>             "afterDistinct(category)",
>             "afterDistinct(searchable(publisher))",
>           )
>       ),
>   )
> ```
>
> ```php PHP theme={"system"}
> $response = $client->setSettings(
>     'INDEX_NAME',
>     ['attributesForFaceting' => [
>         'author',
>
>         'filterOnly(isbn)',
>
>         'searchable(edition)',
>
>         'afterDistinct(category)',
>
>         'afterDistinct(searchable(publisher))',
>     ],
>     ],
> );
> ```
>
> ```python Python theme={"system"}
> response = client.set_settings(
>     index_name="INDEX_NAME",
>     index_settings={
>         "attributesForFaceting": [
>             "author",
>             "filterOnly(isbn)",
>             "searchable(edition)",
>             "afterDistinct(category)",
>             "afterDistinct(searchable(publisher))",
>         ],
>     },
> )
> ```
>
> ```ruby Ruby theme={"system"}
> response = client.set_settings(
>   "INDEX_NAME",
>   Algolia::Search::IndexSettings.new(
>     attributes_for_faceting: [
>       "author",
>       "filterOnly(isbn)",
>       "searchable(edition)",
>       "afterDistinct(category)",
>       "afterDistinct(searchable(publisher))"
>     ]
>   )
> )
> ```
>
> ```scala Scala theme={"system"}
> val response = Await.result(
>   client.setSettings(
>     indexName = "INDEX_NAME",
>     indexSettings = IndexSettings(
>       attributesForFaceting = Some(
>         Seq(
>           "author",
>           "filterOnly(isbn)",
>           "searchable(edition)",
>           "afterDistinct(category)",
>           "afterDistinct(searchable(publisher))"
>         )
>       )
>     )
>   ),
>   Duration(100, "sec")
> )
> ```
>
> ```swift Swift theme={"system"}
> let response = try await client.setSettings(
>     indexName: "INDEX_NAME",
>     indexSettings: IndexSettings(attributesForFaceting: [
>         "author",
>         "filterOnly(isbn)",
>         "searchable(edition)",
>         "afterDistinct(category)",
>         "afterDistinct(searchable(publisher))",
>     ])
> )
> ```> [accordion] Legacy API clients
>
> ```cs C# theme={"system"}
> IndexSettings settings = new IndexSettings
> {
>   AttributesForFaceting = new List
>   {
>     "author",
>     "filterOnly(isbn)",
>     "searchable(edition)",
>     "afterDistinct(category)",
>     "afterDistinct(searchable(publisher))"
>   }
> };
> ```
>
> ```go Go theme={"system"}
> res, err := index.SetSettings(search.Settings{
> 	AttributesForFaceting: opt.AttributesForFaceting(
> 		"author",
> 		"filterOnly(isbn)",
> 		"searchable(edition)",
> 		"afterDistinct(category)",
> 		"afterDistinct(searchable(publisher))",
> 	),
> })
> ```
>
> ```java Java theme={"system"}
> index.setSettings(
>   new IndexSettings().setAttributesForFaceting(Arrays.asList(
>     "author",
>     "filterOnly(isbn)",
>     "searchable(edition)",
>     "afterDistinct(category)",
>     "afterDistinct(searchable(publisher))"
>   ))
> );
> ```
>
> ```js JavaScript theme={"system"}
> index
>   .setSettings({
>     attributesForFaceting: [
>       "author",
>       "filterOnly(isbn)",
>       "searchable(edition)",
>       "afterDistinct(category)",
>       "afterDistinct(searchable(publisher))",
>     ],
>   })
>   .then(() => {
>     // done
>   });
> ```
>
> ```kotlin Kotlin theme={"system"}
> val settings = settings {
>     attributesForFaceting {
>         +"author"
>         +FilterOnly("isbn")
>         +Searchable("edition")
>     }
> }
>
> index.setSettings(settings)
> ```
>
> ```php PHP theme={"system"}
> $index->setSettings([
>   'attributesForFaceting' => [
>     "author",
>     "filterOnly(isbn)",
>     "searchable(edition)",
>     "afterDistinct(category)",
>     "afterDistinct(searchable(publisher))"
>   ]
> ]);
> ```
>
> ```python Python theme={"system"}
> index.set_settings(
>     {
>         "attributesForFaceting": [
>             "author",
>             "filterOnly(isbn)",
>             "searchable(edition)",
>             "afterDistinct(category)",
>             "afterDistinct(searchable(publisher))",
>         ]
>     }
> )
> ```
>
> ```ruby Ruby theme={"system"}
> index.set_settings(
>   {
>     attributesForFaceting: [
>       "author",
>       "filterOnly(isbn)",
>       "searchable(edition)",
>       "afterDistinct(category)",
>       "afterDistinct(searchable(publisher))"
>     ]
>   }
> )
> ```
>
> ```scala Scala theme={"system"}
> client.execute {
>   setSettings of "myIndex" `with` IndexSettings(
>     attributesForFaceting = Some(Seq(
>       "author",
>       "filterOnly(isbn)",
>       "searchable(edition)",
>       "afterDistinct(category)",
>       "afterDistinct(searchable(publisher))",
>     ))
>   )
> }
> ```
>
> ```swift Swift theme={"system"}
> let settings = Settings()
>   .set(\.attributesForFaceting, to: [
>     "author",
>     .filterOnly("isbn"),
>     .searchable("edition")
>   ])
>
> index.setSettings(settings) { result in
>   if case .success(let response) = result {
>     print("Response: \(response)")
>   }
> }
> ```
