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

# Filtering

> How does filtering work with Algolia? Learn how Algolia enables filtered searches.

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

Filtering allows your users to drill down and create a smaller, more manageable set of results based on meaningful categories.
It gives them direct control over the <Records /> they query.
Categories can be brand, color, or genre of film.
They can be dress or shoe sizes or price ranges like "expensive" or "cheap".

The most common use for filtering is to provide a UI that enables users to refine their search using one or more clickable items.

## How to filter your data

1. [Define filterable attributes (at indexing time)](#define-filterable-attributes)
2. [Filter by attributes (at query time)](#filter-by-attributes)

Most [records have one or more attributes](/doc/guides/sending-and-managing-data/prepare-your-data#algolia-records), such as color, brand, genre, or category, that you can choose as a filter.
A filter attribute can be a list of single words, more complex phrases, numbers, boolean values, dates, or even arrays and nested arrays of related data.
Users may use any filter combination to group records.
Filtering creates more targeted and therefore relevant subsets of results, and increases the chance that only the best results appear at the top.

### Define filterable attributes

First, define filter attributes as attributes for faceting.
You can do this on the [dashboard](https://www.algolia.com/ecommerce-merchandising-playbook/configuring-faceting/) or with an [API client](/doc/guides/managing-results/refine-results/faceting/how-to/declaring-attributes-for-faceting).

If you only want to use an attribute for filtering, use the [`filterOnly`](/doc/api-reference/api-parameters/attributesForFaceting#param-filter-only) modifier.
This reduces the <Index /> size and improves search speed.
For example, if you plan to filter on an attribute, such as `color`, but don't need to calculate or display the number of items with `color:green`, `color:blue`, or similar,  use `filterOnly`.

<Info>
  If you use [`filters`](/doc/api-reference/api-parameters/filters) or [`numericFilters`](/doc/api-reference/api-parameters/numericFilters) to filter on **numeric** attributes, you don't need to set these attributes as `attributesForFaceting`.
</Info>

### Filter by attributes

* **[Filter by string](/doc/guides/managing-results/refine-results/filtering/how-to/filter-by-attributes#filter-by-string)**
* **[Filter by numeric value](/doc/guides/managing-results/refine-results/filtering/how-to/filter-by-attributes#filter-by-numeric-value)**
* **[Filter by date](/doc/guides/managing-results/refine-results/filtering/how-to/filter-by-attributes#filter-by-date)**
* **[Filter by array](/doc/guides/managing-results/refine-results/filtering/how-to/filter-by-attributes#filter-by-array)**
* **[Filter by tags](/doc/guides/managing-results/refine-results/filtering/how-to/filter-by-attributes#filter-by-tags)**
* **[Filter by boolean](/doc/guides/managing-results/refine-results/filtering/how-to/filter-by-attributes#filter-by-boolean)**
* **[Filter by null or missing attributes](/doc/guides/managing-results/refine-results/filtering/how-to/filter-by-attributes#filter-by-null-or-missing-attributes)**
* **[Filter by `objectID`](/doc/guides/managing-results/refine-results/filtering/how-to/filter-by-attributes#filter-by-objectid)**

## How to apply filtering to the search UI

After defining [filterable attributes](#define-filterable-attributes) and ensuring users can filter every record [with the appropriate attributes](#filter-by-attributes), ensure your frontend represents all these possibilities by using InstantSearch's [refinements](/doc/api-reference/widgets/refinement-list/js).

You'll typically want to display all filtering categories. Thus, if you have created two filters, `brand` and `price_range`, you'll always want to display a list of brands and a price range slider for every query in your UI.
For example, a search for "phones" returns brands like Apple and Samsung, while a search for "speakers" returns Panasonic and Bose.
While the values may change, the `brand` filter is always present.

To learn more, see:

* [Facet drop down](/doc/guides/building-search-ui/ui-and-ux-patterns/facet-dropdown/js)
* [Guided search](/doc/guides/solutions/ecommerce/filtering-and-navigation/tutorials/guided-search)
* [UI design: filter and sort panel](/doc/guides/building-search-ui/resources/ui-kit/js#filter-and-sort-panel)

## Other uses for filtering

Although the most common use for filtering is to enable users to refine their search and limit the records they search within,
there are other ways to use filters. For example:

* [Security-filtering](/doc/guides/security/api-keys/how-to/user-restricted-access-to-data): using filters as a security measure, where each user has access to only their private data.
* [Geo-filtering](/doc/guides/managing-results/refine-results/geolocation#geographical-filtering-and-sorting): filtering on user's geolocation (if your index has geographical data).
* [Filter scoring](/doc/guides/managing-results/refine-results/filtering/in-depth/filter-scoring): using filters to help promote some records over others.
* [Query-based filtering](/doc/guides/managing-results/rules/detecting-intent): setting rules that parse your users' queries and use specific query terms as filters instead of search terms.
  For example, if a user types in "red", "red" can be used as a filter instead of a search term, thereby returning all red records.
