Type: list of strings
Engine default: [] (no facets retrieved)
Parameter syntax
'facets' => [
  'attribute',
  ...
]
Parameter syntax
facets: [
  'attribute',
  ...
]
Parameter syntax
facets: [
  'attribute',
  ...
]
Parameter syntax
'facets': [
  'attribute',
  ...
]
Parameter syntax
query.facets = [
  "attribute",
  ...
]
Parameter syntax
.setFacets(
  "attribute",
  ...
)
Parameter syntax
.SetFacets(new string[] {
  "attribute",
  ...
})
Parameter syntax
.setFacets(Arrays.asList(
  "attribute",
  ...
))
Parameter syntax
"facets": []string{
  "attribute",
  ...
}
Parameter syntax
facets = Some(Seq(
  "attribute",
  ...
))

Can be used in these methods:
search, browse, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey search, browse, search_for_facet_values, generate_secured_api_key, add_api_key, update_api_key search, browse, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey search, browse, search_for_facet_values, generate_secured_api_key, add_api_key, update_api_key search, browse, searchForFacetValues searchAsync, browseAsync, searchForFacetValues Search, Browse, SearchForFacetValues, GenerateSecuredApiKey, AddApiKey, UpdateApiKey Search, browse, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey Search, Browse, SearchForFacetValues, GenerateSecuredAPIKey, AddAPIKey, UpdateAPIKey search, browse index, search into facet values, generateSecuredApiKey, add key, update key

About this parameter

Facets to retrieve.

The effect of this setting: For each of the retrieved facets (eg. color; size), the response will contain a list of facet values (blue, red; small, large, …) in objects matching the current query. Each value will be returned with its associated count (number of matched objects containing that value).

The maximum number of facet values returned depends on the maxValuesPerFacet setting. The default is 100 and the max is 1000.

By default, the returned values are sorted by frequency, but this can be changed to alphabetical with sortFacetValuesBy.


Usage notes:
  • Facets must have been declared beforehand in the attributesForFaceting index setting.

  • Faceting does not filter your results. If you want to filter results, you should use filters.

  • Default/Empty list: If not specified or empty, no facets are retrieved. The special value * may be used to retrieve all facets.

  • Approximating facet counts: If the number of hits is high, facet counts may be approximate. The response field exhaustiveFacetsCount is true when the count is exact.

Examples

Only retrieve faceting data for some attributes

For this example, let’s consider that attributesForFaceting are set to: ["category", "author", "nb_views", "nb_downloads"] but, for the current search, you want to retrieve facet values only for category and author.

<?php
$results = $index->search('query', [
  'facets' => ['category', 'author']
]);
results = index.search('query', {
  facets: ['category', 'author']
})
index.search({
  query: 'query',
  facets: ['category', 'author']
}).then(res => {
  // console.log(res);
});
results = index.search('query', {
  'facets': ['category', 'author']
})
let query = Query(query: "query")
query.facets = ["category", "author"]

index.search(query, completionHandler: { (res, error) in
  print(res)
})
index.search(new Query("query").setFacets("category", "author"));
index.search(
  new Query("query").SetFacets(new string[] { "category", "author" })
);
index.search(
  new Query("query").setFacets(Arrays.asList(
    "category",
    "author"
  ))
);
res, err := index.Search("query", algoliasearch.Map{
  "facets": []string{
    "category",
    "author",
  },
})
client.execute {
  search into "myIndex" query Query(
    query = Some("query"),
    facets = Some(Seq(
      "category",
      "author"
    ))
  )
}
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala