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

# facets

> Retrieve facets, their facet values, and the number of matching facet values

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

export const serviceLimits = {
  application: {
    applicationSize: "100 GB (or 1 GB for the Build plan)",
    indexSize: "100 GB (or 1 GB for the Build plan)",
    indexingOperations: "Depends on your plan and usage.",
    indexingRate: "10,000 indexing operations per Unit (as applicable)",
    indexingRequestBodySize: "1 GB per batch",
    indicesPerApplication: "1,000 (Premium), 50 (Grow), or 10 (Build)",
    customNormalizations: "10",
    pendingRequests: "5,000",
    recordSize: "10 KB to 100 KB—based on your plan (10 KB maximum for the Build plan)",
    searchRequestBodySize: "50 MB per request",
    sortCriterionLength: "First 50 bytes (50 characters for ASCII text)",
    synonymsPerIndex: "10,000 (or 1,000 for the Build plan)",
    throttlingLimit: "100 pending requests",
    virtualReplicasPerIndex: "20"
  },
  filtersFacetsRules: {
    conditionsPerRule: "25",
    filterScore: "65,535",
    maxRatioFacetValuePairs: "0.1",
    numberOfFilters: "1,000",
    promotedItemsPerGroup: "100",
    promotedItemsPerRule: "300",
    ruleConsequenceSize: "100 KiB",
    queryParameterSize: "16 KiB",
    valuesPerFacetPerQuery: "1,000",
    reorderedFacetsPerQuery: "20",
    reorderedFacetValuesPerQuery: "20",
    precomputedFacetOrderingQueries: "100,000"
  },
  searchUI: {
    pagination: "20,000",
    querySuggestions: "100",
    querySize: "512 bytes"
  },
  insightsAnalytics: {
    analyticsApiCalls: "100 API calls per minute per app",
    tagSize: "100 characters",
    tagsProcessedPerIndex: "1,750 unique tag combinations every 5 minutes",
    topSearches: "1,000"
  },
  security: {
    apiKeys: "5,000"
  },
  connectors: {
    authenticationsPerApp: "200",
    sourcesPerApp: "100",
    destinationsPerApp: "500",
    tasksPerSource: "10",
    pushPayloadSize: "5 MB per API call",
    pushWatchDuration: "3 minutes",
    jsonFileSize: "1 GB",
    jsonFileRows: "1,000,000",
    csvFileSize: "1 GB",
    csvFileRows: "1,000,000",
    pushEndpointRate: "2000 calls per minute per IP",
    observabilityRate: "2000 calls per minute per IP",
    runTaskRate: "10 calls per 10 minute per taskID",
    otherEndpointsRate: "200 calls per minute per IP"
  },
  dataTransformation: {
    codeSize: "32 kB",
    runtime: "1 second per transformation",
    memory: "100 kB per request",
    transformationsPerApplication: "5 million per month",
    fetchEnrichmentRequests: "Up to 1 million Fetch requests per Application per month, as part the 5 million transformations per Application per month limit.",
    fetchTimeout: "30 seconds per Record",
    fetchResponseSize: "128 kB"
  },
  collections: {
    collectionsPerIndex: "500 (Premium plan) or 1,000 (Elevate plan)",
    conditionsPerCollection: "50",
    manuallySelectedItemsPerCollection: "10,000",
    objectIdSize: "200 characters"
  },
  smartGroups: {
    groupsPerCuratedQuery: "3",
    recordsPerGroup: "50",
    highestStartPosition: "100",
    compositionsPerApplication: "100",
    compositionRulesPerComposition: "200",
    disjunctiveFacetsPerRequest: "20",
    hitsPerPage: "1000"
  },
  docSearch: {
    applicationSize: "25 GB",
    indexSize: "25 GB",
    recordSize: "100 kB",
    indicesPerApplication: "20",
    queriesPerSecond: "3",
    teamMembers: "10"
  },
  generativeGuides: {
    guidesPerIndex: "1,000",
    sizePerGuide: "100 kB",
    inputTokensPerGeneration: "50,000",
    outputTokensPerGeneration: "2,000"
  },
  agentStudio: {
    conversationsRetained: "100,000",
    completionsPerMinute: "3,000",
    retentionPolicy: "90 days",
    agentsPerApp: "500"
  }
};

<Setting type="list<string>" default="[]" defaultNote="no facets retrieved" scope="search" />

The `facets` parameter lets you retrieve facet values and their match counts for each specified attribute.

For each specified attribute, such as `color`, `size`, or `category`, the response includes:

* A list of facet values (for example: `blue`, `red`, `small`)
* The number of matching records for each value
* An `exhaustive` object indicating whether the values or counts are complete

To learn more, see [Retrieve facets](/doc/guides/managing-results/refine-results/faceting#retrieve-facets).

## Usage

* To retrieve counts for all available facets, use the wildcard: `["*"]`.
* Declare all attributes you want to facet on with [`attributesForFaceting`](/doc/api-reference/api-parameters/attributesForFaceting).
* **Facets don't filter results**.
  Use the [`filters`](/doc/api-reference/api-parameters/filters) parameter to apply filtering.
* Facet values are **sorted by frequency** by default.
  Use [`sortFacetValuesBy`](/doc/api-reference/api-parameters/sortFacetValuesBy) to change the sort order.
* Each facet value is truncated to a maximum of 1,000 characters.
* The number of facet values returned per facet is limited by [`maxValuesPerFacet`](/doc/api-reference/api-parameters/maxValuesPerFacet) (default: 100, max: {serviceLimits.filtersFacetsRules.valuesPerFacetPerQuery}).
* The number of facet attributes that can be retrieved is limited to 1,000.
* The response includes two optional properties:

  * `facetsCount`: `true` if facet counts are complete, `false` if facet counts are approximate.
  * `facetValues`: `true` if all facet values were retrieved, `false` otherwise.

<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.SearchSingleIndexAsync<Hit>(
        "INDEX_NAME",
        new SearchParams(
          new SearchParamsObject
          {
            Query = "query",
            Facets = new List<string> { "category", "author" },
          }
        )
      );
      ```

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

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

      ```java Java theme={"system"}
      SearchResponse response = client.searchSingleIndex(
        "INDEX_NAME",
        new SearchParamsObject().setQuery("query").setFacets(Arrays.asList("category", "author")),
        Hit.class
      );
      ```

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

      ```kotlin Kotlin theme={"system"}
      var response =
        client.searchSingleIndex(
          indexName = "INDEX_NAME",
          searchParams = SearchParamsObject(query = "query", facets = listOf("category", "author")),
        )
      ```

      ```php PHP theme={"system"}
      $response = $client->searchSingleIndex(
          'INDEX_NAME',
          ['query' => 'query',
              'facets' => [
                  'category',

                  'author',
              ],
          ],
      );
      ```

      ```python Python theme={"system"}
      response = client.search_single_index(
          index_name="INDEX_NAME",
          search_params={
              "query": "query",
              "facets": [
                  "category",
                  "author",
              ],
          },
      )
      ```

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

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

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

  <Accordion title="Legacy API clients">
    <CodeGroup>
      ```cs C# theme={"system"}
      index.Search(new Query("query")
      {
          Facets = new List{ "category", "author" }
      });
      ```

      ```go Go theme={"system"}
      res, err := index.Search(
      	"query",
      	opt.Facets("category", "author"),
      )
      ```

      ```java Java theme={"system"}
      index.search(
        new Query("query").setFacets(Arrays.asList(
          "category",
          "author"
        ))
      );
      ```

      ```js JavaScript theme={"system"}
      index
        .search("query", {
          facets: ["category", "author"],
        })
        .then((results) => {
          console.log(results);
        });
      ```

      ```kotlin Kotlin theme={"system"}
      val query = query("query") {
          facets {
              +"category"
              +"author"
          }
      }

      index.search(query)
      ```

      ```php PHP theme={"system"}
      $results = $index->search('query', [
        'facets' => ['category', 'author']
      ]);
      ```

      ```python Python theme={"system"}
      results = index.search("query", {"facets": ["category", "author"]})
      ```

      ```ruby Ruby theme={"system"}
      results = index.search(
        "query",
        {
          facets: ["category", "author"]
        }
      )
      ```

      ```scala Scala theme={"system"}
      client.execute {
        search into "myIndex" query Query(
          query = Some("query"),
          facets = Some(Seq(
            "category",
            "author"
          ))
        )
      }
      ```

      ```swift Swift theme={"system"}
      let query = Query("query")
        .set(\.facets, to: ["category", "author"])

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

The example response shows three matches for "Jhon" in the `author` facet and one in the `category` facet for "Classical".
The facet count is exact.

```jsonc icon=braces theme={"system"}
{
  "facets": {
    "author": {
      "Jhon": 3,
    },
    "category": {
      "Classical": 1,
    }
  },
  "exhaustiveFacetsCount": true,
  "exhaustive": {
    "facetsCount": true
  },
  "hits": {
    //...
  }
}
```
