> ## Documentation Index
> Fetch the complete documentation index at: https://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

export const Setting = ({type, default: defaultValue, defaultNote, scope, min, max, formerly}) => {
  const renderedDefault = defaultValue === '' ? '""' : defaultValue;
  const renderedNote = defaultNote ? `(${defaultNote})` : '';
  return <ul>
      <li><strong>Type:</strong> <code>{type}</code></li>
      <li><strong>Default:</strong> <code>{renderedDefault}</code>{renderedNote}</li>
      {min && <li><strong>Min:</strong> <code>{min}</code></li>}
      {max && <li><strong>Max:</strong> <code>{max}</code></li>}
      <li><strong>Scope:</strong> <a href="/doc/api-reference/api-parameters"><code>{scope}</code></a></li>
      {formerly && <li>
          <strong>Deprecated name:</strong> <code>{formerly}</code>
        </li>}
    </ul>;
};

<Setting type="list<string>" default="[]" defaultNote="no facets" scope="settings" />

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](/doc/guides/managing-results/refine-results/faceting/how-to/declaring-attributes-for-faceting).

<Info>
  There's no hard limit on the number of attributes you can include,
  but adding too many can slow down [`getSettings`](/doc/rest-api/search/get-settings) operations
  and degrade performance in the Algolia dashboard.
</Info>

## Usage

* Attribute names are case-sensitive
* Declaring an attribute here enables:
  * **Faceting**—use attributes inside [facets](/doc/guides/managing-results/refine-results/faceting)
  * **Filtering**—use attributes inside [`filters`](/doc/api-reference/api-parameters/filters), [`facetFilters`](/doc/api-reference/api-parameters/facetFilters), and [`optionalFilters`](/doc/api-reference/api-parameters/optionalFilters)
* You can use [nested attributes](/doc/guides/managing-results/refine-results/faceting#hierarchical-facets) for faceting, such as `authors.mainAuthor`. In this case, only `mainAuthor` is used for faceting.
* Avoid colons (`:`) in facet attribute names faceting as the `filters` syntax uses colons as delimiters.

## Modifiers

Use *modifiers* to change the behavior of faceted attributes.

<ParamField path="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.
  </Note>
</ParamField>

<ParamField path="searchable">
  Makes a facet searchable—users can type to [find facet values](/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.
  </Note>
</ParamField>

<ParamField path="afterDistinct">
  Ensures facet counts reflect only unique records when using the [`distinct`](/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`](/doc/api-reference/api-parameters/facetingAfterDistinct) is also set to `true`, it takes precendence and applies to all the query's facets.

  You can combine this modifier with `searchable`: `afterDistinct(searchable(attribute))`.
</ParamField>

## Example

The 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

<AccordionGroup>
  <Accordion title="Current API clients" defaultOpen="true">
    <CodeGroup>
      ```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))",
          ])
      )
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Legacy API clients">
    <CodeGroup>
      ```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)")
        }
      }
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>
