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

# disablePrefixOnAttributes

> Attributes for which to turn off prefix search

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>;
};

<Settings type="list<string>" default="[]" scope="settings,search" />

The `disablePrefixOnAttributes` parameter turns off prefix matching for the specified attributes.

This is useful when you want to ensure only full-word matches are allowed—for example,
in attributes like SKUs, phone numbers, or serial codes—where partial matches could produce irrelevant results.

For more information, see [Prefix searching by attribute](/doc/guides/managing-results/optimize-search-results/override-search-engine-defaults/in-depth/prefix-searching#per-attribute-prefix-behavior).

## Usage

* Attribute names are case-sensitive.
* To turn off prefix matching for an attribute, ensure it's listed as a separate entry in [`searchableAttributes`](/doc/api-reference/api-parameters/searchableAttributes). Attributes [with equal priority](/doc/guides/managing-results/must-do/searchable-attributes/how-to/configuring-searchable-attributes-the-right-way#searchable-attributes-with-the-same-priority) (grouped together as a single entry) can't be targeted by `disablePrefixOnAttributes`. For example:

  ```json theme={"system"}
  [
    'sku',
    'barcode,serial_number,buzz' 
  ]
  ```

<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>

## Example

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

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

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

      ```java Java theme={"system"}
      UpdatedAtResponse response = client.setSettings(
        "INDEX_NAME",
        new IndexSettings().setDisablePrefixOnAttributes(Arrays.asList("serial_number"))
      );
      ```

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

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

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

      ```python Python theme={"system"}
      response = client.set_settings(
          index_name="INDEX_NAME",
          index_settings={
              "disablePrefixOnAttributes": [
                  "serial_number",
              ],
          },
      )
      ```

      ```ruby Ruby theme={"system"}
      response = client.set_settings(
        "INDEX_NAME",
        Algolia::Search::IndexSettings.new(disable_prefix_on_attributes: ["serial_number"])
      )
      ```

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

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

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

      index.SetSettings(settings);
      ```

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

      ```java Java theme={"system"}
      index.setSettings(
        new IndexSettings()
          .setDisablePrefixOnAttributes(
            Collections.singletonList("sku")
          )
      );
      ```

      ```js JavaScript theme={"system"}
      index
        .setSettings({
          disablePrefixOnAttributes: ["sku"],
        })
        .then(() => {
          // done
        });
      ```

      ```kotlin Kotlin theme={"system"}
      val settings = settings {
          disablePrefixOnAttributes { +"sku" }
      }

      index.setSettings(settings)
      ```

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

      ```python Python theme={"system"}
      index.set_settings(
          {
              "disablePrefixOnAttributes": [
                  "sku",
              ]
          }
      )
      ```

      ```ruby Ruby theme={"system"}
      index.set_settings(
        {
          disablePrefixOnAttributes: [
            "sku"
          ]
        }
      )
      ```

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

      ```swift Swift theme={"system"}
      let settings = Settings()
        .set(\.disablePrefixOnAttributes, to: ["sku"])

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