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

# Multilingual search

> Learn how to implement search that can handle multiple languages.

export const Records = () => <Tooltip tip="A record is a searchable object in an Algolia index. Each record consists of named attributes." cta="Algolia records" href="/doc/guides/sending-and-managing-data/prepare-your-data#algolia-records">
    records
  </Tooltip>;

export const Index = () => <Tooltip tip="An Algolia index is a searchable dataset that consists of records and configuration settings. These settings define how the records are searched and ranked.">
    index
  </Tooltip>;

Algolia supports all writing systems and [many languages](/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/supported-languages),
including symbol-based languages such as Chinese and Japanese.
Algolia also handles multiple languages on the same website/app, meaning some users could search in French and some in English, using the same Algolia account.

The purpose of this guide is to explain how to organize your indices to enable multi-language search.

## Using one or multiple indices to handle multi-language search

Depending on your use case, you can use either one <Index /> for each language or one for all languages.

[Use multiple indices, one for each language](#one-index-per-language), if:

* You need a [custom ranking](/doc/guides/managing-results/must-do/custom-ranking) per language/country.
  For example, you want to sort by price, and there are different pricing structures in different countries.
* You want to support many languages.

[Use one index for all languages](#one-index-for-all-records),
if you want to support querying in multiple languages.
For example, an Arabic-speaking user might use Arabic text for some words and the Roman alphabet for brand names.

## One index per language

This approach simplifies:

* Index configuration
* Per-language analytics (otherwise, you need to use [`analyticsTags`](/doc/api-reference/api-parameters/analyticsTags))
* Creation of per-language [query suggestions](/doc/guides/building-search-ui/ui-and-ux-patterns/query-suggestions/js).

In this solution, you create one index per language:

```json JSON icon=braces theme={"system"}
[
  {
    "objectID": 1,
    "title": "The Wolf of Wall Street"
  }
]
```

```json JSON icon=braces theme={"system"}
[
  {
    "objectID": 1,
    "title": "Le loup de Wall Street"
  }
]
```

```json JSON icon=braces theme={"system"}
[
  {
    "objectID": 1,
    "title": "El lobo de Wall Street"
  }
]
```

Once your <Records /> are in different indices,
you can select which index to target from the frontend.

## One index for all records

<Check>
  Before deciding on this approach, check that all the text you require from your list of supported languages will be within
  [Algolia's record size limits](https://support.algolia.com/hc/en-us/articles/4406981897617-Is-there-a-size-limit-for-my-index-records-). If they do exceed the limit, **use [one index per language](#one-index-per-language)**.
</Check>

In this solution, you create one index for all languages. Your records contain text for each language and look like this:

```json JSON icon=braces theme={"system"}
[
  {
    "objectID": 1,
    "title_eng": "The Wolf of Wall Street",
    "title_fr": "Le Loup de Wall Street",
    "title_es": "El lobo de Wall Street"
  }
]
```

You now need to set the searchable attributes for all languages using `searchableAttributes`.
To run the code examples on this page, [install the latest API client](/doc/libraries/sdk/install).

<CodeGroup>
  ```cs C# theme={"system"}
  var response = await client.SetSettingsAsync(
    "INDEX_NAME",
    new IndexSettings
    {
      SearchableAttributes = new List<string> { "title_eng", "title_fr", "title_es" },
    }
  );
  ```

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

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

  ```java Java theme={"system"}
  UpdatedAtResponse response = client.setSettings(
    "INDEX_NAME",
    new IndexSettings().setSearchableAttributes(Arrays.asList("title_eng", "title_fr", "title_es"))
  );
  ```

  ```js JavaScript theme={"system"}
  const response = await client.setSettings({
    indexName: 'movies',
    indexSettings: { searchableAttributes: ['title_eng', 'title_fr', 'title_es'] },
  });
  ```

  ```kotlin Kotlin theme={"system"}
  var response =
    client.setSettings(
      indexName = "INDEX_NAME",
      indexSettings =
        IndexSettings(searchableAttributes = listOf("title_eng", "title_fr", "title_es")),
    )
  ```

  ```php PHP theme={"system"}
  $response = $client->setSettings(
      'INDEX_NAME',
      ['searchableAttributes' => [
          'title_eng',

          'title_fr',

          'title_es',
      ],
      ],
  );
  ```

  ```python Python theme={"system"}
  response = client.set_settings(
      index_name="INDEX_NAME",
      index_settings={
          "searchableAttributes": [
              "title_eng",
              "title_fr",
              "title_es",
          ],
      },
  )
  ```

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

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

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

Then at query time you must specify which attributes you want to be searchable,
depending on the user's language. Here's how to do this with the JavaScript API client:

<CodeGroup>
  ```cs C# theme={"system"}
  var response = await client.SearchSingleIndexAsync<Hit>(
    "INDEX_NAME",
    new SearchParams(
      new SearchParamsObject
      {
        Query = "wolf",
        RestrictSearchableAttributes = new List<string> { "title_fr" },
      }
    )
  );
  ```

  ```dart Dart theme={"system"}
  final response = await client.searchSingleIndex(
    indexName: "INDEX_NAME",
    searchParams: SearchParamsObject(
      query: "wolf",
      restrictSearchableAttributes: [
        "title_fr",
      ],
    ),
  );
  ```

  ```go Go theme={"system"}
  response, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest(
    "INDEX_NAME").WithSearchParams(search.SearchParamsObjectAsSearchParams(
    search.NewEmptySearchParamsObject().SetQuery("wolf").SetRestrictSearchableAttributes(
      []string{"title_fr"}))))
  if err != nil {
    // handle the eventual error
    panic(err)
  }
  ```

  ```java Java theme={"system"}
  SearchResponse response = client.searchSingleIndex(
    "INDEX_NAME",
    new SearchParamsObject().setQuery("wolf").setRestrictSearchableAttributes(Arrays.asList("title_fr")),
    Hit.class
  );
  ```

  ```js JavaScript theme={"system"}
  const response = await client.searchSingleIndex({
    indexName: 'indexName',
    searchParams: { query: 'wolf', restrictSearchableAttributes: ['title_fr'] },
  });
  ```

  ```kotlin Kotlin theme={"system"}
  var response =
    client.searchSingleIndex(
      indexName = "INDEX_NAME",
      searchParams =
        SearchParamsObject(query = "wolf", restrictSearchableAttributes = listOf("title_fr")),
    )
  ```

  ```php PHP theme={"system"}
  $response = $client->searchSingleIndex(
      'INDEX_NAME',
      ['query' => 'wolf',
          'restrictSearchableAttributes' => [
              'title_fr',
          ],
      ],
  );
  ```

  ```python Python theme={"system"}
  response = client.search_single_index(
      index_name="INDEX_NAME",
      search_params={
          "query": "wolf",
          "restrictSearchableAttributes": [
              "title_fr",
          ],
      },
  )
  ```

  ```ruby Ruby theme={"system"}
  response = client.search_single_index(
    "INDEX_NAME",
    Algolia::Search::SearchParamsObject.new(query: "wolf", restrict_searchable_attributes: ["title_fr"])
  )
  ```

  ```scala Scala theme={"system"}
  val response = Await.result(
    client.searchSingleIndex(
      indexName = "INDEX_NAME",
      searchParams = Some(
        SearchParamsObject(
          query = Some("wolf"),
          restrictSearchableAttributes = Some(Seq("title_fr"))
        )
      )
    ),
    Duration(100, "sec")
  )
  ```

  ```swift Swift theme={"system"}
  let response: SearchResponse<Hit> = try await client.searchSingleIndex(
      indexName: "INDEX_NAME",
      searchParams: SearchSearchParams.searchSearchParamsObject(SearchSearchParamsObject(
          query: "wolf",
          restrictSearchableAttributes: ["title_fr"]
      ))
  )
  ```
</CodeGroup>
