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

# attributesToSnippet

> Attributes to snippet

\<ul><li>**Type:** `list<string>`</li>
      \<li>**Default:** `[]`</li>
      
      
      \<li>**Scope:** [`settings,search`](https://www.algolia.com/doc/api-reference/api-parameters)</li></ul>The `attributesToSnippet` parameter defines which attributes should return **[snippets](https://www.algolia.com/doc/guides/building-search-ui/ui-and-ux-patterns/highlighting-snippeting/js.md#snippeting)**—short text fragments surrounding matched query terms.## Usage- The default snippet length is **10 words** unless otherwise specified, for example `"content:80"`.
- Use `"*"` to apply snippets to all attributes.
- To turn off snippeting, pass an empty array (`[]`).
- Snippeting is limited to the first **50,000 characters** per result (or 5,000 logograms for CJK languages).
- When enabled, the search response includes a `_snippetResult` object.### `_snippetResult`**\_snippetResult.value** `string`The snippeted text, with highlighting tags applied.
If truncated, the snippet ends with an ellipsis (`…` by default).
Customize the ellipsis with [`snippetEllipsisText`](https://www.algolia.com/doc/api-reference/api-parameters/snippetEllipsisText).**\_snippetResult.matchLevel** `enum\<string\>`Indicates how closely the attribute matched the search query.
Possible values: `none`, `partial`, `full`.## Examples### Set default attributes to snippet> [accordion] Current API clients
>
> ```cs C# theme={"system"}
> var response = await client.SetSettingsAsync(
>   "INDEX_NAME",
>   new IndexSettings
>   {
>     AttributesToSnippet = new List<string> { "content:80", "description" },
>   }
> );
> ```
>
> ```dart Dart theme={"system"}
> final response = await client.setSettings(
>   indexName: "INDEX_NAME",
>   indexSettings: IndexSettings(
>     attributesToSnippet: [
>       "content:80",
>       "description",
>     ],
>   ),
> );
> ```
>
> ```go Go theme={"system"}
> response, err := client.SetSettings(client.NewApiSetSettingsRequest(
>   "INDEX_NAME",
>   search.NewEmptyIndexSettings().SetAttributesToSnippet(
>     []string{"content:80", "description"})))
> if err != nil {
>   // handle the eventual error
>   panic(err)
> }
> ```
>
> ```java Java theme={"system"}
> UpdatedAtResponse response = client.setSettings(
>   "INDEX_NAME",
>   new IndexSettings().setAttributesToSnippet(Arrays.asList("content:80", "description"))
> );
> ```
>
> ```js JavaScript theme={"system"}
> const response = await client.setSettings({
>   indexName: 'theIndexName',
>   indexSettings: { attributesToSnippet: ['content:80', 'description'] },
> });
> ```
>
> ```kotlin Kotlin theme={"system"}
> var response =
>   client.setSettings(
>     indexName = "INDEX_NAME",
>     indexSettings = IndexSettings(attributesToSnippet = listOf("content:80", "description")),
>   )
> ```
>
> ```php PHP theme={"system"}
> $response = $client->setSettings(
>     'INDEX_NAME',
>     ['attributesToSnippet' => [
>         'content:80',
>
>         'description',
>     ],
>     ],
> );
> ```
>
> ```python Python theme={"system"}
> response = client.set_settings(
>     index_name="INDEX_NAME",
>     index_settings={
>         "attributesToSnippet": [
>             "content:80",
>             "description",
>         ],
>     },
> )
> ```
>
> ```ruby Ruby theme={"system"}
> response = client.set_settings(
>   "INDEX_NAME",
>   Algolia::Search::IndexSettings.new(attributes_to_snippet: ["content:80", "description"])
> )
> ```
>
> ```scala Scala theme={"system"}
> val response = Await.result(
>   client.setSettings(
>     indexName = "INDEX_NAME",
>     indexSettings = IndexSettings(
>       attributesToSnippet = Some(Seq("content:80", "description"))
>     )
>   ),
>   Duration(100, "sec")
> )
> ```
>
> ```swift Swift theme={"system"}
> let response = try await client.setSettings(
>     indexName: "INDEX_NAME",
>     indexSettings: IndexSettings(attributesToSnippet: ["content:80", "description"])
> )
> ```> [accordion] Legacy API clients
>
> ```cs C# theme={"system"}
> IndexSettings settings = new IndexSettings()
> settings.AttributesToSnippet = new List
> {
>     "content:80",
>     "description"
> };
>
> index.SetSettings(settings);
> ```
>
> ```go Go theme={"system"}
> res, err := index.SetSettings(search.Settings{
> 	AttributesToSnippet: opt.AttributesToSnippet(
> 		"content:80",
> 		"description",
> 	),
> })
> ```
>
> ```java Java theme={"system"}
> index.setSettings(
>   new IndexSettings()
>     .setAttributesToSnippet(
>       Arrays.asList(
>         "content:80",
>         "description"
>       )
>     )
> );
> ```
>
> ```js JavaScript theme={"system"}
> index
>   .setSettings({
>     attributesToSnippet: ["content:80", "description"],
>   })
>   .then(() => {
>     // done
>   });
> ```
>
> ```kotlin Kotlin theme={"system"}
> val settings = settings {
>     attributesToSnippet {
>         +"content"(80)
>         +"description"
>     }
> }
>
> index.setSettings(settings)
> ```
>
> ```php PHP theme={"system"}
> $index->setSettings([
>   'attributesToSnippet' => [
>     'content:80',
>     'description'
>   ]
> ]);
> ```
>
> ```python Python theme={"system"}
> index.set_settings({"attributesToSnippet": ["content:80", "description"]})
> ```
>
> ```ruby Ruby theme={"system"}
> index.set_settings(
>   {
>     attributesToSnippet: [
>       "content:80",
>       "description"
>     ]
>   }
> )
> ```
>
> ```scala Scala theme={"system"}
> client.execute {
>   setSettings of "myIndex" `with` IndexSettings(
>     attributesToSnippet = Some(Seq(
>       "content:80",
>       "description",
>     ))
>   )
> }
> ```
>
> ```swift Swift theme={"system"}
> let settings = Settings()
>   .set(\.attributesToSnippet, to: [
>     .init(attribute: "content", count: 80),
>     .init(attribute: "description")
>   ])
>
> index.setSettings(settings) { result in
>   if case .success(let response) = result {
>     print("Response: \(response)")
>   }
> }
> ```### Snippet all attributes by default> [accordion] Current API clients
>
> ```cs C# theme={"system"}
> var response = await client.SetSettingsAsync(
>   "INDEX_NAME",
>   new IndexSettings { AttributesToSnippet = new List<string> { "*:80" } }
> );
> ```
>
> ```dart Dart theme={"system"}
> final response = await client.setSettings(
>   indexName: "INDEX_NAME",
>   indexSettings: IndexSettings(
>     attributesToSnippet: [
>       "*:80",
>     ],
>   ),
> );
> ```
>
> ```go Go theme={"system"}
> response, err := client.SetSettings(client.NewApiSetSettingsRequest(
>   "INDEX_NAME",
>   search.NewEmptyIndexSettings().SetAttributesToSnippet(
>     []string{"*:80"})))
> if err != nil {
>   // handle the eventual error
>   panic(err)
> }
> ```
>
> ```java Java theme={"system"}
> UpdatedAtResponse response = client.setSettings("INDEX_NAME", new IndexSettings().setAttributesToSnippet(Arrays.asList("*:80")));
> ```
>
> ```js JavaScript theme={"system"}
> const response = await client.setSettings({
>   indexName: 'theIndexName',
>   indexSettings: { attributesToSnippet: ['*:80'] },
> });
> ```
>
> ```kotlin Kotlin theme={"system"}
> var response =
>   client.setSettings(
>     indexName = "INDEX_NAME",
>     indexSettings = IndexSettings(attributesToSnippet = listOf("*:80")),
>   )
> ```
>
> ```php PHP theme={"system"}
> $response = $client->setSettings(
>     'INDEX_NAME',
>     ['attributesToSnippet' => [
>         '*:80',
>     ],
>     ],
> );
> ```
>
> ```python Python theme={"system"}
> response = client.set_settings(
>     index_name="INDEX_NAME",
>     index_settings={
>         "attributesToSnippet": [
>             "*:80",
>         ],
>     },
> )
> ```
>
> ```ruby Ruby theme={"system"}
> response = client.set_settings(
>   "INDEX_NAME",
>   Algolia::Search::IndexSettings.new(attributes_to_snippet: ["*:80"])
> )
> ```
>
> ```scala Scala theme={"system"}
> val response = Await.result(
>   client.setSettings(
>     indexName = "INDEX_NAME",
>     indexSettings = IndexSettings(
>       attributesToSnippet = Some(Seq("*:80"))
>     )
>   ),
>   Duration(100, "sec")
> )
> ```
>
> ```swift Swift theme={"system"}
> let response = try await client.setSettings(
>     indexName: "INDEX_NAME",
>     indexSettings: IndexSettings(attributesToSnippet: ["*:80"])
> )
> ```> [accordion] Legacy API clients
>
> ```cs C# theme={"system"}
> IndexSettings settings = new IndexSettings()
> settings.AttributesToSnippet = new List
> {
>     "*:80"
> };
>
> index.SetSettings(settings);
> ```
>
> ```go Go theme={"system"}
> res, err := index.SetSettings(search.Settings{
> 	AttributesToSnippet: opt.AttributesToSnippet(
> 		"*:80",
> 	),
> })
> ```
>
> ```java Java theme={"system"}
> index.setSettings(
>   new IndexSettings()
>     .setAttributesToSnippet(
>       Arrays.asList(
>         "*:80"
>       )
>     )
> );
> ```
>
> ```js JavaScript theme={"system"}
> index
>   .setSettings({
>     attributesToSnippet: ["*:80"],
>   })
>   .then(() => {
>     // done
>   });
> ```
>
> ```kotlin Kotlin theme={"system"}
> val settings = settings {
>     attributesToSnippet {
>         +"*"(80)
>     }
> }
>
> index.setSettings(settings)
> ```
>
> ```php PHP theme={"system"}
> $index->setSettings([
>   'attributesToSnippet' => [
>     "*:80"
>   ]
> ]);
> ```
>
> ```python Python theme={"system"}
> index.set_settings({"attributesToSnippet": ["*:80"]})
> ```
>
> ```ruby Ruby theme={"system"}
> index.set_settings(
>   {
>     attributesToSnippet: [
>       "*:80"
>     ]
>   }
> )
> ```
>
> ```scala Scala theme={"system"}
> client.execute {
>   setSettings of "myIndex" `with` IndexSettings(
>     attributesToSnippet = Some(Seq(
>       "*:80"
>     ))
>   )
> }
> ```
>
> ```swift Swift theme={"system"}
> let settings = Settings()
>   .set(\.attributesToSnippet, to: [
>     .init(attribute: "*", count: 80)
>   ])
>
> index.setSettings(settings) { result in
>   if case .success(let response) = result {
>     print("Response: \(response)")
>   }
> }
> ```### Override default attributes to snippet for the current search> [accordion] Current API clients
>
> ```cs C# theme={"system"}
> var response = await client.SearchSingleIndexAsync<Hit>(
>   "INDEX_NAME",
>   new SearchParams(
>     new SearchParamsObject
>     {
>       Query = "query",
>       AttributesToSnippet = new List<string> { "title", "content:80" },
>     }
>   )
> );
> ```
>
> ```dart Dart theme={"system"}
> final response = await client.searchSingleIndex(
>   indexName: "INDEX_NAME",
>   searchParams: SearchParamsObject(
>     query: "query",
>     attributesToSnippet: [
>       "title",
>       "content:80",
>     ],
>   ),
> );
> ```
>
> ```go Go theme={"system"}
> response, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest(
>   "INDEX_NAME").WithSearchParams(search.SearchParamsObjectAsSearchParams(
>   search.NewEmptySearchParamsObject().SetQuery("query").SetAttributesToSnippet(
>     []string{"title", "content:80"}))))
> if err != nil {
>   // handle the eventual error
>   panic(err)
> }
> ```
>
> ```java Java theme={"system"}
> SearchResponse response = client.searchSingleIndex(
>   "INDEX_NAME",
>   new SearchParamsObject().setQuery("query").setAttributesToSnippet(Arrays.asList("title", "content:80")),
>   Hit.class
> );
> ```
>
> ```js JavaScript theme={"system"}
> const response = await client.searchSingleIndex({
>   indexName: 'indexName',
>   searchParams: { query: 'query', attributesToSnippet: ['title', 'content:80'] },
> });
> ```
>
> ```kotlin Kotlin theme={"system"}
> var response =
>   client.searchSingleIndex(
>     indexName = "INDEX_NAME",
>     searchParams =
>       SearchParamsObject(query = "query", attributesToSnippet = listOf("title", "content:80")),
>   )
> ```
>
> ```php PHP theme={"system"}
> $response = $client->searchSingleIndex(
>     'INDEX_NAME',
>     ['query' => 'query',
>         'attributesToSnippet' => [
>             'title',
>
>             'content:80',
>         ],
>     ],
> );
> ```
>
> ```python Python theme={"system"}
> response = client.search_single_index(
>     index_name="INDEX_NAME",
>     search_params={
>         "query": "query",
>         "attributesToSnippet": [
>             "title",
>             "content:80",
>         ],
>     },
> )
> ```
>
> ```ruby Ruby theme={"system"}
> response = client.search_single_index(
>   "INDEX_NAME",
>   Algolia::Search::SearchParamsObject.new(query: "query", attributes_to_snippet: ["title", "content:80"])
> )
> ```
>
> ```scala Scala theme={"system"}
> val response = Await.result(
>   client.searchSingleIndex(
>     indexName = "INDEX_NAME",
>     searchParams = Some(
>       SearchParamsObject(
>         query = Some("query"),
>         attributesToSnippet = Some(Seq("title", "content:80"))
>       )
>     )
>   ),
>   Duration(100, "sec")
> )
> ```
>
> ```swift Swift theme={"system"}
> let response: SearchResponse<Hit> = try await client.searchSingleIndex(
>     indexName: "INDEX_NAME",
>     searchParams: SearchSearchParams.searchSearchParamsObject(SearchSearchParamsObject(
>         query: "query",
>         attributesToSnippet: ["title", "content:80"]
>     ))
> )
> ```> [accordion] Legacy API clients
>
> ```cs C# theme={"system"}
> index.Search(new Query("query")
> {
>     AttributesToSnippet = new List { "title", "content:80" }
> });
> ```
>
> ```go Go theme={"system"}
> res, err := index.Search(
> 	"query",
> 	opt.AttributesToSnippet("title", "content:80"),
> )
> ```
>
> ```java Java theme={"system"}
> index.search(
>   new Query("query")
>     .setAttributesToSnippet(
>       Arrays.asList(
>         "title",
>         "content:80"
>       )
>     )
> );
> ```
>
> ```js JavaScript theme={"system"}
> index
>   .search("query", {
>     attributesToSnippet: ["title", "content:80"],
>   })
>   .then(({ hits }) => {
>     console.log(hits);
>   });
> ```
>
> ```kotlin Kotlin theme={"system"}
> val query = query("query") {
>     attributesToSnippet {
>         +"title"
>         +"content"(80)
>     }
> }
>
> index.search(query)
> ```
>
> ```php PHP theme={"system"}
> $results = $index->search('query', [
>   'attributesToSnippet' => [
>     "title",
>     "content:80"
>   ]
> ]);
> ```
>
> ```python Python theme={"system"}
> results = index.search("query", {"attributesToSnippet": ["title", "content:80"]})
> ```
>
> ```ruby Ruby theme={"system"}
> results = index.search(
>   "query",
>   {
>     attributesToSnippet: [
>       "title",
>       "content:80"
>     ]
>   }
> )
> ```
>
> ```scala Scala theme={"system"}
> client.execute {
>   search into "myIndex" query Query(
>     query = Some("query"),
>     attributesToSnippet = Some(Seq(
>       "title",
>       "content:80"
>     ))
>   )
> }
> ```
>
> ```swift Swift theme={"system"}
> let query = Query("query")
>   .set(\.attributesToSnippet, to: [
>     .init(attribute: "title"),
>     .init(attribute: "content", count: 80)
>   ])
>
> index.search(query: query) { result in
>   if case .success(let response) = result {
>     print("Response: \(response)")
>   }
> }
> ```
