---
title: Implement facets
slug: '3199'
canonical_url: https://docs.coveo.com/en/3199/
collection: build-a-search-ui
source_format: adoc
---
# Implement facets

A [search interface](https://docs.coveo.com/en/2741.md) often includes [facets](https://docs.coveo.com/en/198.md) that allow the user to narrow down a [query](https://docs.coveo.com/en/231.md) to a specific subset of result [items](https://docs.coveo.com/en/210.md) by selecting one or more dynamic [filter](https://docs.coveo.com/en/2736.md) values.
This article provides guidelines for implementing _facets_ on your own, assuming that you can't use the [Coveo JavaScript Search Framework](https://docs.coveo.com/en/187.md) or the [Atomic](https://docs.coveo.com/en/lcdf0264.md) or [Headless](https://docs.coveo.com/en/lcdf0493.md) libraries in your custom search integration with the [Coveo Platform](https://docs.coveo.com/en/186.md).

> **Note**
>
> As a reference, you may want to look at the source code of the [`DynamicFacet`](https://coveo.github.io/search-ui/components/dynamicfacet.html) component to see how it's implemented in the [Coveo JavaScript Search Framework](https://docs.coveo.com/en/187.md).

> **Warning**
>
> Prior to September 2024, these guidelines instructed users to log facet-specific `customData` in addition to the current `facetState` object.
> The `customData` object is now deprecated and should no longer be used, since the `facetState` object is sufficient to log facet interactions.

## Standard facet actions

The following table lists some actions that you may want to make available in a facet implementation.

Every action belongs to a specific [Coveo Analytics event](https://docs.coveo.com/en/260.md) category, and each entry indicates the `actionCause`, `eventType` and `eventValue` values that [must be logged](https://docs.coveo.com/en/1373.md) when the action is performed.
Each entry also includes a link to the corresponding implementation guidelines.

| Facet action | [Coveo Analytics event](https://docs.coveo.com/en/260.md) | `actionCause` | `eventType` | `eventValue` | Implementation guidelines |
|---|---|---|---|---|---|
| Select a value | Search | `facetSelect` / `documentField` | N/A | N/A | [Toggle facet values](#toggle-facet-values) |
| Un-select a value | Search | `facetDeselect` / `documentField` / `breadcrumbFacet` | N/A | N/A | [Toggle facet values](#toggle-facet-values) |
| Reset selected | Search | `facetClearAll` / `breadcrumbResetAll` | N/A | N/A | [Toggle facet values](#toggle-facet-values) |
| Request more values | Custom | `showMoreFacetResults` | `dynamicFacet` | `showMoreFacetResults` | [Request additional facet values](#request-additional-facet-values) |
| Request less values | Custom | `showLessFacetResults` | `dynamicFacet` | `showLessFacetResults` | [Request additional facet values](#request-additional-facet-values) |
| Search for a value | N/A | N/A | N/A | N/A | [Perform facet search](#perform-facet-search) |

> **Note**
>
> It's important to use the correct `actionCause`, `eventType` and `eventValue` values when logging an [event](https://docs.coveo.com/en/260.md) for a specific type of action in a [search interface](https://docs.coveo.com/en/2741.md).
> Otherwise:
>
> * [Coveo Analytics reports](https://docs.coveo.com/en/266.md) may become incoherent in the underlying [Coveo organization](https://docs.coveo.com/en/185.md), especially if that [organization](https://docs.coveo.com/en/185.md) powers both [Coveo JavaScript Search Framework](https://docs.coveo.com/en/187.md) and custom [search interfaces](https://docs.coveo.com/en/2741.md).
>
> * The [Coveo ML](https://docs.coveo.com/en/188.md) service may not function properly.

## Request and render facets

Conceptually, a [facet](https://docs.coveo.com/en/198.md) relies on an existing [field](https://docs.coveo.com/en/200.md) (for example, `@bookauthor`) to render a sorted list of [facet](https://docs.coveo.com/en/198.md) values (for example, `Ernest Hemingway`, `Mark Twain`), each of which is accompanied by an estimated number of occurrences in the current [query](https://docs.coveo.com/en/231.md) result set.

You can request the necessary data to render one or more [facets](https://docs.coveo.com/en/198.md) through the [`facets`](https://docs.coveo.com/en/13.md#operation/searchUsingPost-facets) query parameter.
Each valid [object](https://docs.coveo.com/en/13.md#operation/searchUsingPost-facets) you include in the `facets` query parameter will populate a distinct object in the `facets` array of that [query](https://docs.coveo.com/en/231.md) response body.

Most of the time, when a [query](https://docs.coveo.com/en/231.md) is sent from a faceted [search interface](https://docs.coveo.com/en/2741.md), you'll want to request and render or update [facets](https://docs.coveo.com/en/198.md).
To do so, prepare a new [query](https://docs.coveo.com/en/231.md).
In the request body:

1. In the [`facets`](https://docs.coveo.com/en/13.md#operation/searchUsingPost-facets) query parameter, include a corresponding [`facet`](https://docs.coveo.com/en/13.md#operation/searchUsingPost-facets) object for each facet to display in the [search interface](https://docs.coveo.com/en/2741.md).

1. In the `facet` object operation, set [`field`](https://docs.coveo.com/en/13.md#operation/searchUsingPost-facets) to the name of the [field](https://docs.coveo.com/en/200.md) that the [facet](https://docs.coveo.com/en/198.md) is based on (for example, `@bookauthor`).

When the Search API returns, for each [facet](https://docs.coveo.com/en/198.md) to render in the [search interface](https://docs.coveo.com/en/2741.md): [[step2]]

1. In the [query](https://docs.coveo.com/en/231.md) response body, retrieve the object in the `facets` array whose `field` value matches the [field](https://docs.coveo.com/en/200.md) on which the [facet](https://docs.coveo.com/en/198.md) relies.

1. Use the `value`, `numberOfResults`, and `state` attributes of each object in the `values` array from the [query](https://docs.coveo.com/en/231.md) response to render or update the [facet](https://docs.coveo.com/en/198.md).

Call the Usage Analytics Write API to [log the corresponding search event](https://docs.coveo.com/en/1502.md).
In the request body, include an object containing the following key-value pairs in the `facetState` property for each non-idle [facet](https://docs.coveo.com/en/198.md) value:

* `"facetType": <TYPE>`

* `"field": <FIELDNAME>`

* `"id": <ID>`

* `"state": <STATE>`

* `"value": <VALUE>`

* `"displayValue": <DISPLAY_VALUE>` (optional)

* `"facetPosition": <FACET_POSITION>` (optional)

* `"title": <TITLE>` (optional)

* `"valuePosition": <VALUE_POSITION>` (optional)

where:

* `<TYPE>` (string) is the [facet](https://docs.coveo.com/en/198.md) data type (for example, `specific`).

* `<FIELDNAME>` (string) is the `@`-prefixed name of the [field](https://docs.coveo.com/en/200.md) that this [facet](https://docs.coveo.com/en/198.md) is based on (for example, `@booklength`).

* `<ID>` (string) is the unique identifier of the [facet](https://docs.coveo.com/en/198.md) in which one or more values were toggled.
Typically, this is the `@`-prefixed name of the [field](https://docs.coveo.com/en/200.md) that this [facet](https://docs.coveo.com/en/198.md) is based on (for example, `@booklength`).

* `<STATE>` (string) is the current state of the [facet](https://docs.coveo.com/en/198.md) value (either `auto_selected` or `selected`).

* `<VALUE>` (string) is the name of the toggled [facet](https://docs.coveo.com/en/198.md) value (for example, `Hardcover`).

* `<DISPLAY_VALUE>` (string) is the display name of the [facet](https://docs.coveo.com/en/198.md) value (for example, `Hardcover`).

* `<FACET_POSITION>` (integer) is the 1-based position of the [facet](https://docs.coveo.com/en/198.md) (for example, `1`).

* `<TITLE>` (string) is the [facet](https://docs.coveo.com/en/198.md) title (for example, `Format`)

* `<VALUE_POSITION>` (integer) is the 1-based position of the value in the [facet](https://docs.coveo.com/en/198.md) (for example, `2`).

### Examples of requesting and rendering facets

1. A customer accesses the Books4Fun [search interface](https://docs.coveo.com/en/2741.md).
Once loaded, the [search interface](https://docs.coveo.com/en/2741.md) retrieves and renders the _Book Format_ and _Author_ [facets](https://docs.coveo.com/en/198.md) with the following request:
+
```http
POST https://<ORG_ID>.org.coveo.com/rest/search/v2 HTTP/1.1

Accept: application/json
Content-Type: application/json
Authorization: Bearer **********-****-****-****-************
```
+
> **HIPAA endpoint**
>
> For a [HIPAA organization](https://docs.coveo.com/en/1853.md), replace `org.coveo.com` with `orghipaa.coveo.com`.

+
**Payload (excerpt)**
+
```json
{
  ...
  "q": "Doctor Sleep",
  "cq": "NOT @source==\"Movies4Fun\"",
  ...
  "facets": [
    {
      "facetId": "@bookformat",
      "field": "bookformat",
      "type": "specific",
      "currentValues": [],
      ...
    },
    {
      "field": "bookauthor",
      "facetId": "@bookauthor",
      "type": "specific",
      "currentValues": [],
      ...
    }
  ],
  ...
}
```
+
**200 OK response body (excerpt)**
+
```json
{
  ...
  "facets": [
    {
      "facetId": "@bookformat",
      "field": "bookformat",
      "moreValuesAvailable": true,
      "values": [
        {
          "value": "Hardcover",
          "state": "idle",
          "numberOfResults": 83
        },
        {
          "value": "Softcover",
          "state": "idle",
          "numberOfResults": 47
        },
        ...
      ],
      "indexScore": 0.435
    },
    {
      "facetId": "@bookauthor",
      "field": "bookauthor",
      "moreValuesAvailable": true,
      "values": [
        {
          "value": "Charles Dickens",
          "state": "idle",
          "numberOfResults": 24
        },
        {
          "value": "Ernest Hemingway",
          "state": "idle",
          "numberOfResults": 26
        },
        {
          "value": "Mark Twain",
          "state": "idle",
          "numberOfResults": 23
        },
        ...
      ],
      "indexScore": 0.435
    }
  ],
  ...
}
```

1. Logging a search event for this action:

   ```http
   POST https://myorgid.analytics.org.coveo.com/rest/ua/v15/analytics/searches?visitor=********-****-****-******** HTTP/1.1
   ​
   Accept: application/json
   Content-Type: application/json
   Authorization: Bearer **********-****-****-****-************
   ```

   **Payload (excerpt)**

   ```json
   [
     {
       "actionCause": "interfaceLoad",
       ...
       "facetState": []
     }
   ]
   ```

## Toggle facet values

In a typical [faceted](https://docs.coveo.com/en/198.md) [search interface](https://docs.coveo.com/en/2741.md), the user can toggle (that is, select or un-select) any number of [facet](https://docs.coveo.com/en/198.md) values to alter the [`facets`](https://docs.coveo.com/en/13.md#operation/searchUsingPost-facets) [query](https://docs.coveo.com/en/231.md) parameter.
When the user interacts with a [facet](https://docs.coveo.com/en/198.md) in this way, prepare a new [query](https://docs.coveo.com/en/231.md).
For each [facet](https://docs.coveo.com/en/198.md) currently displayed in the [search interface](https://docs.coveo.com/en/2741.md), include a corresponding object in the `facets` [query](https://docs.coveo.com/en/231.md) parameter:

1. Set `facetId` to the unique identifier of the [facet](https://docs.coveo.com/en/198.md).

1. Set `field` to the [field](https://docs.coveo.com/en/200.md) name that the [facet](https://docs.coveo.com/en/198.md) is based on.

1. Set `type` to `specific`.

1. If the [facet](https://docs.coveo.com/en/198.md) is the one that was just interacted with, set `freezeCurrentValues` to `true`.

1. If more than the originally specified `numberOfResults` are being requested for the [facet](https://docs.coveo.com/en/198.md), set `isFieldExpanded` to `true` (see [Request additional facet values](#request-additional-facet-values)).

1. For each value currently displayed in the [facet](https://docs.coveo.com/en/198.md), include a corresponding object in the [`currentValues`](https://docs.coveo.com/en/13.md#tag/Search-V2/operation/searchUsingGet-facets-currentValues) array:

   1. Set the `value` property to the value of the current [facet](https://docs.coveo.com/en/198.md).

   1. Set the `state` property to `idle` if the [facet](https://docs.coveo.com/en/198.md) isn't selected, or set it to `selected` otherwise.

   1. Set `preventAutoSelect` property to `false` to ensure that [Coveo ML](https://docs.coveo.com/en/188.md) automatically selects the [facet](https://docs.coveo.com/en/198.md) value.

1. Call the Search API to [execute this query](https://docs.coveo.com/en/1445.md).

When the Search API returns, call the Usage Analytics Write API to [log the corresponding search event](https://docs.coveo.com/en/1502.md).
In the request body:

1. Set the `actionCause` property to:

  * `facetSelect` if the user has selected a single [facet](https://docs.coveo.com/en/198.md) value.

  * `facetUnselect` if the user has un-selected a single [facet](https://docs.coveo.com/en/198.md) value.

  * `facetClearAll` if the user has cleared all previously selected values.

1. For each non-idle [facet](https://docs.coveo.com/en/198.md), include an object containing the following key-value pairs in the `facetState` property:

   --
  * `"facetType": <TYPE>`

  * `"field": <FIELDNAME>`

  * `"id": <ID>`

  * `"state": <STATE>`

  * `"value": <VALUE>`

  * `"displayValue": <DISPLAY_VALUE>`(optional)

  * `"facetPosition": <FACET_POSITION>` (optional)

  * `"title": <TITLE>`(optional)

  * `"valuePosition": <VALUE_POSITION>` (optional)
--
+
where:
+
--
  * `<TYPE>` (string) is the [facet](https://docs.coveo.com/en/198.md) data type (for example, `specific`).

  * `<FIELDNAME>` (string) is the `@`-prefixed name of the [field](https://docs.coveo.com/en/200.md) that this [facet](https://docs.coveo.com/en/198.md) is based on (for example, `@booklength`).

  * `<ID>` (string) is the unique identifier of the [facet](https://docs.coveo.com/en/198.md) in which one or more values were toggled.
Typically, this is the `@`-prefixed name of the [field](https://docs.coveo.com/en/200.md) that this [facet](https://docs.coveo.com/en/198.md) is based on (for example, `@booklength`).

  * `<STATE>` (string) is the current state of the [facet](https://docs.coveo.com/en/198.md) value (either `auto_selected` or `selected`).

  * `<VALUE>` (string) is the name of the toggled [facet](https://docs.coveo.com/en/198.md) value (for example, `Hardcover`).

  * `<DISPLAY_VALUE>` (string) is the display name of the [facet](https://docs.coveo.com/en/198.md) value (for example, `Hardcover`).

  * `<FACET_POSITION>` (integer) is the 1-based position of the [facet](https://docs.coveo.com/en/198.md) (for example, `1`).

  * `<TITLE>` (string) is the [facet](https://docs.coveo.com/en/198.md) title (for example, `Format`)

  * `<VALUE_POSITION>` (integer) is the 1-based position of the value in the [facet](https://docs.coveo.com/en/198.md) (for example, `2`).
--

1. Set other required or optional properties as needed, such as `language`, `[originLevel1](https://docs.coveo.com/en/1337.md)`, or `[originLevel2](https://docs.coveo.com/en/1338.md)`.

When the Usage Analytics Write API returns successfully:

1. [Update all of the facets](#request-and-render-facets) in the [search interface](https://docs.coveo.com/en/2741.md).

1. [Update the result list](https://docs.coveo.com/en/1372.md#render-query-results).

### Interact with a facet indirectly

The [Coveo JavaScript Search Framework](https://docs.coveo.com/en/187.md) includes components that allow users to interact with [facets](https://docs.coveo.com/en/198.md) indirectly, such as the [`Breadcrumb`](https://coveo.github.io/search-ui/components/breadcrumb.html) and [`FieldValue`](https://coveo.github.io/search-ui/components/fieldvalue.html) components.

If you implement your own components, be sure to use the appropriate `actionCause` value when logging a search [event](https://docs.coveo.com/en/260.md) after the user has indirectly toggled one or more [facet](https://docs.coveo.com/en/198.md) values:

| Action | `actionCause` |
|---|---|
| Select or un-select a single [facet](https://docs.coveo.com/en/198.md) value by interacting with a [query](https://docs.coveo.com/en/231.md) result | `documentField` |
| Un-select a single [facet](https://docs.coveo.com/en/198.md) value by interacting with [breadcrumbs](https://docs.coveo.com/en/2731.md) | `breadcrumbFacet` |
| Clear all selected [facet](https://docs.coveo.com/en/198.md) values by interacting with [breadcrumbs](https://docs.coveo.com/en/2731.md) | `breadcrumbResetAll` |

### Examples of toggling facet values

1. A customer is browsing products on the Books4Fun site.
They select the `Hardcover` value from the _Book Format_ facet, which executes the following query:
+
```http
POST https://<ORG_ID>.org.coveo.com/rest/search/v2 HTTP/1.1

Accept: application/json
Content-Type: application/json
Authorization: Bearer **********-****-****-****-************
```
+
> **HIPAA endpoint**
>
> For a [HIPAA organization](https://docs.coveo.com/en/1853.md), replace `org.coveo.com` with `orghipaa.coveo.com`.

+
**Payload (excerpt)**
+
```json
{
  ...
  "q": "Doctor Sleep",
  "cq": "NOT @source==\"Movies4Fun\"",
  ...
  "facets": [
    {
      "facetId": "@bookformat",
      "field": "bookformat",
      "type": "specific",
      "currentValues": [
        {
          "value": "Hardcover",
          "state": "selected",
          "preventAutoSelect": false
        }
        {
          "value": "Softcover",
          "state": "idle",
          "preventAutoSelect": false
        },
        ...
      ],
      "numberOfValues": 3,
      ...
    },
    {
      "field": "bookauthor",
      "facetId": "@bookauthor",
      "type": "specific",
      "currentValues": [
        {
          "value": "Ernest Hemingway",
          "state": "idle",
          "preventAutoSelect": false
        },
        {
          "value": "Mark Twain",
          "state": "idle",
          "preventAutoSelect": false
        }
      ],
      "numberOfValues": 3,
      ...
    }
  ],
  ...
  "language": "en",
  "originLevel1": "Books4FunSearch",
  "originLevel2": "All",
  ...
}
```
+
**200 OK response body (excerpt)**
+
```json
{
  ...
  "facets": [
    {
      "facetId": "@bookformat",
      "field": "bookformat",
      "moreValuesAvailable": true,
      "values": [
        {
          "value": "Hardcover",
          "state": "selected",
          "numberOfResults": 83
        },
        {
          "value": "Softcover",
          "state": "idle",
          "numberOfResults": 47
        },
        ...
      ],
      "indexScore": 0.435
    },
    {
      "facetId": "@bookauthor",
      "field": "bookauthor",
      "moreValuesAvailable": true,
      "values": [
        {
          "value": "Charles Dickens",
          "state": "idle",
          "numberOfResults": 24
        },
        {
          "value": "Ernest Hemingway",
          "state": "idle",
          "numberOfResults": 26
        },
        {
          "value": "Mark Twain",
          "state": "idle",
          "numberOfResults": 23
        },
        ...
      ],
      "indexScore": 0.435
    }
  ],
  ...
}
```

1. Logging a search event for this action:

   ```http
   POST https://myorgid.analytics.org.coveo.com/rest/ua/v15/analytics/searches?visitor=********-****-****-******** HTTP/1.1
   ​
   Accept: application/json
   Content-Type: application/json
   Authorization: Bearer **********-****-****-****-************
   ```

   **Payload (excerpt)**

   ```json
   [
     {
       "actionCause": "facetSelect",
       "eventType": "dynamicFacet",
       ...
       "facetState": [
         {
           "field": "@bookformat",
           "id": "@bookformat",
           "title": "Format",
           "facetType": "specific",
           "facetPosition": 1,
           "value": "Hardcover",
           "valuePosition": 2,
           "displayValue": "Hardcover",
           "state": "selected"
         }
       ]
     }
   ]
   ```

## Request additional facet values

The [`numberOfValues`](https://docs.coveo.com/en/13.md#operation/searchUsingPost-facets-numberOfValues) [facet](https://docs.coveo.com/en/198.md) request parameter lets you specify the maximum number of [facet](https://docs.coveo.com/en/198.md) values that the [index](https://docs.coveo.com/en/204.md) may retrieve to populate the `values` array of a given `facet` object (the default value is `8`).

You may also want to allow the user to autonomously request to display more values in a [facet](https://docs.coveo.com/en/198.md).
When the user interacts with a [facet](https://docs.coveo.com/en/198.md) in this way, prepare a new [query](https://docs.coveo.com/en/231.md):

1. Set the [`numberOfResults`](https://docs.coveo.com/en/13.md#operation/searchUsingPost-numberOfResults) [query](https://docs.coveo.com/en/231.md) parameter to `0`.

1. In the [`facets`](https://docs.coveo.com/en/13.md#operation/searchUsingPost-facets) [query](https://docs.coveo.com/en/231.md) parameter, include the [`facet`](https://docs.coveo.com/en/13.md#operation/searchUsingPost-facets) object for which the user has requested additional values.

1. In the `facet` object operation, set [`field`](https://docs.coveo.com/en/13.md#operation/searchUsingPost-facets) to the name of the [field](https://docs.coveo.com/en/200.md) that the [facet](https://docs.coveo.com/en/198.md) is based on (for example, `@bookauthor`).

1. For each value currently displayed in the [facet](https://docs.coveo.com/en/198.md), include a corresponding object in the [`currentValues`](https://docs.coveo.com/en/13.md#operation/searchUsingPost-facets) array:

   1. Set the `value` property to the value of the current [facet](https://docs.coveo.com/en/198.md).

   1. Set the `state` property to `idle` if the [facet](https://docs.coveo.com/en/198.md) isn't selected, or set it to `selected` otherwise.

   1. Set `preventAutoSelect` property to `false` to ensure that [Coveo ML](https://docs.coveo.com/en/188.md) automatically selects the [facet](https://docs.coveo.com/en/198.md) value.

1. Set [`numberOfValues`](https://docs.coveo.com/en/13.md#operation/searchUsingPost-facets-numberOfValues) to a higher value than the one that was specified the last time the [facet](https://docs.coveo.com/en/198.md) was requested (for example, `16`).

1. Set [`isFieldExpanded`](https://docs.coveo.com/en/13.md#operation/searchUsingPost-facets-isFieldExpanded) to `true`.

1. Set all of the other [facet](https://docs.coveo.com/en/198.md) request parameters to the same values as the last time the [facet](https://docs.coveo.com/en/198.md) was requested.

> **Note**
>
> Although this [query](https://docs.coveo.com/en/231.md) isn't meant to return actual result [items](https://docs.coveo.com/en/210.md), you should include the other search request parameters as usual.
> This way, it will represent the current state of the [search interface](https://docs.coveo.com/en/2741.md), aside from `numberOfResults` being forcefully set to `0` and `facets` not necessarily containing all of the operations required to update [facets](https://docs.coveo.com/en/198.md).
> Otherwise, the retrieved `facets` object may not contain accurate or consistent [facet](https://docs.coveo.com/en/198.md) values or occurrence counts.

1. Call the Search API to [execute this query](https://docs.coveo.com/en/1445.md).

When the Search API returns, call the Usage Analytics Write API to [log the corresponding custom event](https://docs.coveo.com/en/2650.md).
In the request body:

1. Set the `actionCause` property to `showMoreFacetResults` when showing more results or `showLessFacetResults` when showing less.

1. Set the `eventType` property to `dynamicFacet`.

1. Set the `eventValue` property to `showMoreFacetResults` when showing more results or `showLessFacetResults` when showing less.

1. Set other required or optional properties as needed, such as `language`, `[originLevel1](https://docs.coveo.com/en/1337.md)`, or `[originLevel2](https://docs.coveo.com/en/1338.md)`.

When the Usage Analytics Write API returns successfully, [re-render the facet](#step2) as appropriate.

### Examples of requesting additional facet values

1. A customer is browsing products on the Books4Fun site.
They can't find their favourite author among the currently rendered values in the _Author_ [facet](https://docs.coveo.com/en/198.md), so they request to display more values.
This interaction executes the following request:
+
```http
POST https://<ORG_ID>.org.coveo.com/rest/search/v2 HTTP/1.1

Accept: application/json
Content-Type: application/json
Authorization: Bearer **********-****-****-****-************
```
+
> **HIPAA endpoint**
>
> For a [HIPAA organization](https://docs.coveo.com/en/1853.md), replace `org.coveo.com` with `orghipaa.coveo.com`.

+
**Payload (excerpt)**
+
```json
{
  ...
  "q": "Doctor Sleep",
  "cq": "NOT @source==\"Movies4Fun\"",
  "numberOfResults": 0,
  ...
  "facets": [
    {
      "facetId": "@bookformat",
      "field": "bookformat",
      "type": "specific",
      "currentValues": [
        {
          "value": "Hardcover",
          "state": "selected",
          "preventAutoSelect": false
        }
        {
          "value": "Softcover",
          "state": "idle",
          "preventAutoSelect": false
        },
        ...
      ],
      "numberOfValues": 3,
      ...
    },
    {
      "field": "bookauthor",
      "facetId": "@bookauthor",
      "type": "specific",
      "currentValues": [
        {
          "value": "Ernest Hemingway",
          "state": "idle",
          "preventAutoSelect": false
        },
        {
          "value": "Mark Twain",
          "state": "idle",
          "preventAutoSelect": false
        }
      ],
      "numberOfValues": 6,
      "isFieldExpanded": true,
      ...
    }
  ],
  ...
  "language": "en",
  "originLevel1": "Books4FunSearch",
  "originLevel2": "All",
  ...
}
```
+
**200 OK response body (excerpt)**
+
```json
{
  ...
  "facets": [
    {
      "facetId": "@bookformat",
      "field": "bookformat",
      "moreValuesAvailable": true,
      "values": [
        {
          "value": "Hardcover",
          "state": "selected",
          "numberOfResults": 83
        },
        {
          "value": "Softcover",
          "state": "idle",
          "numberOfResults": 47
        },
        ...
      ],
      "indexScore": 0.435
    },
    {
      "facetId": "@bookauthor",
      "field": "bookauthor",
      "moreValuesAvailable": true,
      "values": [
        {
          "value": "Charles Dickens",
          "state": "idle",
          "numberOfResults": 24
        },
        {
          "value": "Ernest Hemingway",
          "state": "idle",
          "numberOfResults": 26
        },
        {
          "value": "Mark Twain",
          "state": "idle",
          "numberOfResults": 23
        },
        {
          "value": "Stephen King",
          "state": "idle",
          "numberOfResults": 14
        },
        ...
      ],
      "indexScore": 0.435
    }
  ],
  ...
}
```

1. Logging a custom [event](https://docs.coveo.com/en/260.md) for this action:

   ```http
   POST https://myorgid.analytics.org.coveo.com/rest/ua/v15/analytics/custom?visitor=********-****-****-******** HTTP/1.1
   ​
   Accept: application/json
   Content-Type: application/json
   Authorization: Bearer **********-****-****-****-************
   ```

   **Payload (excerpt)**

   ```json
   [
     {
       "actionCause": "showMoreFacetResults",
       "eventType": "dynamicFacet",
       "eventValue": "showMoreFacetResults",
       ...
       "facetState": [
         {
           "field": "@bookformat",
           "id": "@bookformat",
           "title": "Format",
           "facetType": "specific",
           "facetPosition": 1,
           "value": "Hardcover",
           "valuePosition": 2,
           "displayValue": "Hardcover",
           "state": "selected"
         }
       ]
     }
   ]
   ```

## Perform facet search

> **Note**
>
> The following guidelines suggest a [facet](https://docs.coveo.com/en/198.md) search implementation which is similar to that of the [Coveo JavaScript Search Framework](https://docs.coveo.com/en/187.md) (that is, wildcard pattern matching as the user types).
> You may opt to use an entirely different approach for your own implementation.

You may want to allow the user to look for specific [facet](https://docs.coveo.com/en/198.md) values by typing into a dedicated search input within a [facet](https://docs.coveo.com/en/198.md).
When the user interacts with a [facet](https://docs.coveo.com/en/198.md) in this way, on each valid keystroke:

1. Retrieve the current value from the [facet](https://docs.coveo.com/en/198.md) search input (for example, `a`).

1. Prepare a new [facet search request](https://platform.cloud.coveo.com/docs?urls.primaryName=Search%20API#/Search/facetSearch).
In the request body:

   1. Set the `field` property to the name of the [field](https://docs.coveo.com/en/200.md) that the [facet](https://docs.coveo.com/en/198.md) being searched is based on (for example, `bookauthor`).

   1. Set the `query` property to the `**`-prefixed and `**`-suffixed value that was retrieved in step 1 (for example, `a` becomes `**a**`).

   1. Set the `numberOfValues` property to the maximum number of matching values to retrieve through [facet](https://docs.coveo.com/en/198.md) search (for example, `4`).
The default value is `10`.

   1. Set other optional properties as needed, such as `ignoreValues` or `captions`.

1. Set all of the other [facet](https://docs.coveo.com/en/198.md) request parameters to the same values as the last time the [facet](https://docs.coveo.com/en/198.md) was requested.

> **Note**
>
> Although this [query](https://docs.coveo.com/en/231.md) isn't meant to return actual result [items](https://docs.coveo.com/en/210.md), you should include the other search request parameters as usual.
> This way, it will represent the current state of the [search interface](https://docs.coveo.com/en/2741.md), aside from `numberOfResults` being forcefully set to `0` and `facets` not necessarily containing all of the operations required to update [facets](https://docs.coveo.com/en/198.md).
> Otherwise, the retrieved `facets` object may not contain accurate or consistent [facet](https://docs.coveo.com/en/198.md) values or occurrence counts.

1. Call the Search API to [execute this query](https://docs.coveo.com/en/1445.md).

1. When the Search API returns, [render the retrieved facet values](#step2) using the `displayValue` and `count` values of each object in the `values` array in the response body.

### Example of performing facet search

A customer is browsing products on the Books4Fun site.
They can't find their favourite author among the currently rendered values in the _Author_ [facet](https://docs.coveo.com/en/198.md), so they begin typing the author's name into the [facet](https://docs.coveo.com/en/198.md) search box.
This interaction executes the following request:

```http
POST https://myorganizationid9sd8df7s.org.coveo.com/rest/search/v2/facet HTTP/1.1
​
Accept: application/json
Content-Type: application/json
Authorization: Bearer **********-****-****-****-************
```

**Payload (excerpt)**

```json
{
  "field": "bookauthor",
  "numberOfValues": 4,
  "query": "*W*"
}
```

**200 OK response body (excerpt)**

```json
{
  "values": [
    {
      "displayValue": "William Shakespeare",
      "rawValue": "William Shakespeare",
      "count": 10
    },
    {
      "displayValue": "William Faulkner",
      "rawValue": "William Faulkner",
      "count": 5
    },
    ...
  ],
  "moreValuesAvailable": false
}
```