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

# attributeForDistinct

> Attribute for deduplicating or grouping records

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="string" defaultNote="unset" scope="settings" />

The `attributeForDistinct` attribute works in combination with [`distinct`](/doc/api-reference/api-parameters/distinct):

* `attributeForDistinct` establishes groups: all records with the same value of `attributeForDistinct` are treated as a group.
* `distinct` determines how many variants per group are included in the search results.

## Usage

* You can specify only **one** attribute.
* Valid values for the attribute:
  * **String values** are used as-is.
  * **Numbers** are rounded to the nearest integer and converted to strings.
    For example, `1.2` and `1` both become `"1"`.
  * **Boolean** or **null** values are ignored.
  * **Arrays** and **objects** aren't supported and result in unspecified behavior.

## Example

<AccordionGroup>
  <Accordion title="Current API clients" defaultOpen="true">
    <CodeGroup>
      ```cs C# theme={"system"}
      var response = await client.SetSettingsAsync(
        "INDEX_NAME",
        new IndexSettings { AttributeForDistinct = "url" }
      );
      ```

      ```dart Dart theme={"system"}
      final response = await client.setSettings(
        indexName: "INDEX_NAME",
        indexSettings: IndexSettings(
          attributeForDistinct: "url",
        ),
      );
      ```

      ```go Go theme={"system"}
      response, err := client.SetSettings(client.NewApiSetSettingsRequest(
        "INDEX_NAME",
        search.NewEmptyIndexSettings().SetAttributeForDistinct("url")))
      if err != nil {
        // handle the eventual error
        panic(err)
      }
      ```

      ```java Java theme={"system"}
      UpdatedAtResponse response = client.setSettings("INDEX_NAME", new IndexSettings().setAttributeForDistinct("url"));
      ```

      ```js JavaScript theme={"system"}
      const response = await client.setSettings({
        indexName: 'theIndexName',
        indexSettings: { attributeForDistinct: 'url' },
      });
      ```

      ```kotlin Kotlin theme={"system"}
      var response =
        client.setSettings(
          indexName = "INDEX_NAME",
          indexSettings = IndexSettings(attributeForDistinct = "url"),
        )
      ```

      ```php PHP theme={"system"}
      $response = $client->setSettings(
          'INDEX_NAME',
          ['attributeForDistinct' => 'url',
          ],
      );
      ```

      ```python Python theme={"system"}
      response = client.set_settings(
          index_name="INDEX_NAME",
          index_settings={
              "attributeForDistinct": "url",
          },
      )
      ```

      ```ruby Ruby theme={"system"}
      response = client.set_settings("INDEX_NAME", Algolia::Search::IndexSettings.new(attribute_for_distinct: "url"))
      ```

      ```scala Scala theme={"system"}
      val response = Await.result(
        client.setSettings(
          indexName = "INDEX_NAME",
          indexSettings = IndexSettings(
            attributeForDistinct = Some("url")
          )
        ),
        Duration(100, "sec")
      )
      ```

      ```swift Swift theme={"system"}
      let response = try await client.setSettings(
          indexName: "INDEX_NAME",
          indexSettings: IndexSettings(attributeForDistinct: "url")
      )
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Legacy API clients">
    <CodeGroup>
      ```cs C# theme={"system"}
      IndexSettings settings = new IndexSettings();
      settings.AttributeForDistinct = "url";

      index.SetSettings(settings);
      ```

      ```go Go theme={"system"}
      res, err := index.SetSettings(search.Settings{
      	AttributeForDistinct: opt.AttributeForDistinct("url"),
      })
      ```

      ```java Java theme={"system"}
      index.setSettings(
        new IndexSettings()
          .setAttributeForDistinct("url")
      );
      ```

      ```js JavaScript theme={"system"}
      index
        .setSettings({
          attributeForDistinct: "url",
        })
        .then(() => {
          // done
        });
      ```

      ```kotlin Kotlin theme={"system"}
      val settings = settings {
          attributeForDistinct = Attribute("url")
      }

      index.setSettings(settings)
      ```

      ```php PHP theme={"system"}
      $index->setSettings([
        'attributeForDistinct' => 'url'
      ]);
      ```

      ```python Python theme={"system"}
      index.set_settings({"attributeForDistinct": "url"})
      ```

      ```ruby Ruby theme={"system"}
      index.set_settings(
        {
          attributeForDistinct: "url"
        }
      )
      ```

      ```scala Scala theme={"system"}
      client.execute {
        setSettings of "myIndex" `with` IndexSettings(
          attributeForDistinct = Some("url")
        )
      }
      ```

      ```swift Swift theme={"system"}
      let settings = Settings()
        .set(\.attributeForDistinct, to: "url")

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