---
title: Filter and FilterHits
slug: cms-12/docs/filter-and-filterhits
docTags: 
createdAt: 2026-08-10T15:55:59.000Z
---

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 methods 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.

```csharp
var post1 = new BlogPost {
  Author = new Author {
    Name = "Agatha Christie"
  }
};

var post2 = new BlogPost {
  Author = new Author {
    Name = "Agatha Christie"
  }
};

var post3 = new BlogPost {
  Author = new Author {
    Name = "Charles Dickens"
  }
};
```

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.

```csharp
var result = client.Search<BlogPost>()
  .Filter(x => x.Author.Name.Match("Agatha Christie"))
  .TermsFacetFor(x => x.Author.Name)
  .GetResult();

var facetItems = result.TermsFacetFor(x => x.Author.Name);
Console.WriteLine("Using Filter");
foreach(var facetItem in facetItems) {
  Console.WriteLine(facetItem.Term + " (" + facetItem.Count + ")");
}

result = client.Search<BlogPost>()
  .FilterHits(x => x.Author.Name.Match("Agatha Christie"))
  .TermsFacetFor(x => x.Author.Name)
  .GetResult();

facetItems = result.TermsFacetFor(x => x.Author.Name);
Console.WriteLine("Using FilterHits");
foreach(var facetItem in facetItems) {
  Console.WriteLine(facetItem.Term + " (" + facetItem.Count + ")");
}
```

This code produces:

Using Filter
Agatha Christie (2)

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