HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In
GitHubNuGetDev CommunityDoc feedback

Use filters to narrow down search results, or use them for database-like queries. 

There are two extension methods for the `ITypeSearch<TSource>` class filter: `Filter` and `FilterHits`. Both add filters to a search request but do so in different ways.

The Filter method applies a filter to the search query, while `FilterHits` adds a filter to the search request body. Use the `Filter` method in most cases, as it filters the search result and the facets. Use `FilterHits` when you want to apply a filter to search results (the hits) but not to the facets.

You index three blog posts. Two have the same author.

Next, search for blog posts, filter by author to match the one with two posts, and request a terms facet for the author name. First, use the `Filter` method; then, the `FilterHits` method.

This code produces:

Using Filter Agatha Christie (2)

Using FilterHits Agatha Christie (2) Charles Dickens (1)