Full-Text Search in Azure Cosmos DB

Full-text search requests are often unwelcome by DBAs because they place additional strain on databases. Servers must utilize advanced processing techniques to determine whether the desired text exists in a table or container. Although setting up and maintaining full-text search can be challenging, it is essential for modern applications.

Today, users have numerous options at their disposal, and modern systems aim to assist them in quickly finding what they need. One effective method for achieving this is through Full-Text Search functionality, which enables users to efficiently locate products, articles, tickets, and reviews within a database.

Full-text search was introduced to Azure Cosmos DB in 2025. It is simple to set up and use various full-text search functions. Azure Cosmos DB automatically maintains the indexes, so you don’t need to worry about whether the full-text indexes are out of sync.

First, you need to configure the container policies. In the Azure portal, locate the “Full Text Policy” tab, as shown in the following picture. Enter the path of the property for which you would like to run full-text search functions. As of 2025, English is the only available language option. However, documentation indicates that German, Spanish, and French will be supported in the future.

The second step is to add a full-text index to your indexing policies. While full-text functions can operate without an index, doing so will incur significantly higher costs. I strongly recommend adding full-text indexes before you begin using any full-text functions. Whoever is responsible for your Azure Cosmos DB bills will certainly appreciate this proactive step.

Locate the indexing policy file for your container, as shown in the screenshot below, and add the fullTextIndexes array. In my case, I only need to add one path for the PostBody property. However, you can add one or multiple paths to the fullTextIndexes array as needed.

After this step, the data will be processed by language-specific analyzers to ensure efficient and accurate search and ranking. This process removes many stopwords, such as "the," "to," and "an," since these words carry little meaning. By eliminating stopwords, the data becomes lighter and more manageable.

Re-indexing can take a long time to complete, so you need to wait until it’s finished for Azure Cosmos DB to start using the new full-text indexes. This ensures that you receive accurate request charge values when you run any full-text functions. You can monitor the re-indexing progress in real time using the Cosmos DB Studio extension. As shown in the following screenshot, the re-indexing is still in progress, and my full-text search functions are costing me a fortune.

Azure Cosmos DB offers four full-text search functions for your queries.

FullTextContains: Return true if a given string is found within a specified portion of a document. For example, I searched for “SQL Server” in the Stack Overflow dataset, which cost me 25.93 request units (R/U). I have five physical partitions for the Posts container, and since the partition key is not included in the WHERE clause, this query is considered a cross-partition query. Despite being a cross-partition query, this function is very efficient.

FullTextContainsAll: This function returns true if all the specified strings are found within the given property. You can provide multiple keywords when using this function. For example, I searched for the terms “SQL Server” and “performance” in the Stack Overflow dataset. Despite the cross-partition query, Azure Cosmos DB delivered the results quickly, using only 32.94 Request Units.

FullTextContainsAny: This function returns true if any of the specified strings are found within the given property. At least one of the strings must be present in the document for the function to return true. For example, if you search for two words, the function will return true if either of them exists in the document. The number 27.12 RU is also an excellent choice for a cross-partitioning query.

FullTextScore: This function can only be used in an ORDER BY RANK clause and returns a score value for sorting results. As shown in the following screenshot, this function is resource-intensive. However, it can be useful for prioritizing results. I believe it requires fetching all data for ranking, which is why it consumes significantly more Request Units compared to other full-text functions.

In the past, we utilized Azure Search for full-text search capabilities. Now, you can leverage Azure Cosmos DB’s full-text functions, removing dependencies on other products in your architecture diagram.


Leave a Reply

Your email address will not be published. Required fields are marked *