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

The ``Filter`

` method can filter _*numerical*_ fields in several ways. Supported numerical types are int, double, float, long, and their nullable equivalents. Below is a list of use cases and examples illustrating the available methods.

## ## Existence

To search for documents where a numerical field has a value,Â use the ``Exists`

` method. The following search finds blog posts that have an ``AuthorId`

` property; it is similar to the LINQ query ``Where(x => x.AuthorId.HasValue)`

`.

Like all filters, you can negate it with an exclamation point (!). To find all blog posts without an ``AuthorId`

`, use the followingÂ code.

## ## Exact match

For exact matching, use the ``Match`

` method. The followingÂ search matches blog posts with ID 42 but not those with ID 41 or 43. The LINQ equivalentÂ is ``Where(x => x.Id == 42)`

`.

## ## Match by range

To find documents with a numeric field that has a value within a given range,Â use the ``InRange`

` method. The followingÂ search matches blog posts with zero to five comments; it matches blog posts with one, two, three, four, or five comments but not those with six or seven comments.

An equivalent in LINQÂ is ``Where(x => x.NumComments >= 0 && x.NumComments <= 5)`

`.

For some numerical types, such as int, thereÂ are also the ``GreaterThan`

` and ``LessThan`

` methods, whichÂ make range filtering easier. For instance, given that ``NumComments`

` cannot be negative, you can rewrite the previous search.

## ## Match by a set of values

The ``In`

` method lets you filter on ``int`

` fields that match an explicit set of values. For instance, the followingÂ matches blog posts with one, three, or five comments.

## ## Filter on numerical collections

Use the ``Exists`

`, ``In`

`, and ``Match`

` methods for properties that implement ``IEnumerable<int>`

`.

The followingÂ search, whichÂ uses ``Exists`

`,Â matches blog posts that have at least one category ID.

The followingÂ search matches any blog post that has a category with ID 42. It doesÂ not, however, limit the result to blog posts that only have that category ID.