FULLTEXTCONTAINS - Query language in Cosmos DB (in Azure and Fabric)

The FULLTEXTCONTAINS function returns a boolean indicating whether the keyword string expression is contained in a specified property path.

Syntax

FULLTEXTCONTAINS(<property_path>, <string_expr>)

Arguments

Description
property_path The property path to search.
string_expr The string to find.

Return types

Returns a boolean expression.

Examples

This section contains examples of how to use this query language construct.

Full text contains simple example

In this example, the FULLTEXTCONTAINS function is used to return 10 results that contain "search phrase" in the c.text property.

SELECT TOP 10 *
FROM c
WHERE FULLTEXTCONTAINS(c.text, "search phrase")

Full text contains with logical operators

In this example, the FULLTEXTCONTAINS function is used with logical operators to ensure multiple keywords or phrases are included.

SELECT *
FROM c
WHERE FULLTEXTCONTAINS(c.text, "keyword1") AND FULLTEXTCONTAINS(c.text, "keyword2")

Combine FULLTEXTCONTAINS and CONTAINS for precision and performance

In this example, using FULLTEXTCONTAINS instead of CONTAINS dramatically reduces RU consumption because FULLTEXTCONTAINS uses the full-text index.

Query using FULLTEXTCONTAINS

SELECT *
FROM c
WHERE c.PartitionKey = "key"
AND FULLTEXTCONTAINS(c.text, "keyword")

Query using CONTAINS

SELECT *
FROM c
WHERE c.PartitionKey = "key"
AND CONTAINS(c.text, "keyword")

Results from this example. | | FULLTEXTCONTAINS | CONTAINS | | --- | ---: | ---: | | Result count | 234 documents | 32 documents | | Request charge | 3.11 RUs | 12,614 RUs | | Query engine execution time | 0.02 ms | 258.32 ms |

If you need literal substring matches while keeping RU consumption low, use FULLTEXTCONTAINS as a prefilter and then apply CONTAINS to the smaller candidate set:

SELECT *
FROM c
WHERE c.PartitionKey = "key"
AND FULLTEXTCONTAINS(c.text, "keyword")
AND CONTAINS(c.text, "keyword")

In this example, FULLTEXTCONTAINS uses the full-text index to identify documents that match the tokenized search term. CONTAINS then narrows that candidate set to documents whose c.text value contains the literal substring "keyword".

Remarks

  • This function requires enrollment in the Azure Cosmos DB NoSQL Full Text Search feature.
  • This function benefits from a Full Text Index.