Exact match queries

Perform simple exact match queries

An exact match query allows you to select all documents where a field matches a specific value.

You can use exact match queries on several field types. The query syntax varies depending on the type.

The examples in this article use a schema with the following fields:

Field name Field type
description TEXT
condition TAG
price NUMERIC

You can find more details about creating the index and loading the demo data in the quick start guide.

Numeric field

To perform an exact match query on a numeric field, you need to construct a range query with the same start and end value:

FT.SEARCH index "@field:[value value]"

or

FT.SEARCH index "@field:[value]" DIALECT 2 # requires v2.10

or

FT.SEARCH index "@field==value" DIALECT 2 # requires v2.10

As described in the article about range queries, you can also use the FILTER argument:

FT.SEARCH index "*" FILTER field start end

The following examples show you how to query for bicycles with a price of exactly 270 USD:

Tag field

A tag is a short sequence of text, for example, "new" or "Los Angeles".

Important:
If you need to query for short texts, use a tag query instead of a full-text query. Tag fields are more space-efficient for storing index entries and often lead to lower query complexity for exact match queries.

You can construct a tag query for a single tag in the following way:

FT.SEARCH index "@field:{tag}"
Note:
The curly brackets are mandatory for tag queries.

This short example shows you how to query for new bicycles:

Use double quotes and DIALECT 2 for exact match queries involving tags that contain special characters. As of v2.10, the only character that needs escaping in queries involving double-quoted tags is the double-quote character. Here's an example of using double-quoted tags that contain special characters:

Full-text field

A detailed explanation of full-text queries is available in the full-text queries documentation. You can also query for an exact match of a phrase within a text field:

FT.SEARCH index "@field:\"phrase\""
Important:

The phrase must be wrapped by escaped double quotes for an exact match query.

You can't use a phrase that starts with a stop word.

Here is an example for finding all bicycles that have a description containing the exact text 'rough terrain':

RATE THIS PAGE
Back to top ↑