How to query Cosmosdb using FullTextContains with fuzzy search parameters

Alberto Ramirez 0 Reputation points
2025-11-14T21:34:33.5733333+00:00

In my full text search enabled resource container, I'm attempting to use the fuzzy search syntax to find close matches to a search term but receive and error when using the portal or python SDK (4.14.1)

SELECT TOP 10 *

FROM c

WHERE FullTextContains(c.text, {"term": "red", "distance":1})

The fulltextsearch works query correctly when using FullTextContains(c.text, 'red') but not the syntax above for fuzzy search.

Error seen in the portal query window:

{"code":"BadRequest","message":"One of the input values is invalid.\r\nActivityId: ..., Windows/10.0.20348 cosmos-netstandard-sdk/3.18.0"}

Python SDK:

azure.cosmos.exceptions.CosmosHttpResponseError: (BadRequest) One of the input values is invalid. ActivityId: ..., Windows/10.0.20348 cosmos-netstandard-sdk/3.18.0 Code: BadRequest Message: One of the input values is invalid.

The following query works just fine with full text indexing:

Select TOP 10 *

From c

WHERE FullTextContains(c.text, 'red')

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Mahesh Kurva 10,265 Reputation points Microsoft External Staff Moderator
    2025-11-19T16:09:28.6066667+00:00

    Hi Alberto Ramirez •,

    Greetings!!

    Fuzzy search in Cosmos DB is currently a preview feature, so it needs to be enabled before you can use the JSON syntax.

    User's image

    How to fix it:

    1. In the Azure portal, go to your Cosmos DB account → Features → Preview Capabilities and enable Full-Text Search Preview.
    2. Make sure your container has a full-text policy and index for the field you want to search.
    3. After that, you can run queries like
    SELECT TOP 10 *
    FROM c
    WHERE FullTextContains(c.text, {"term":"red","distance":1})
    
    

    For more information, please refer the document: https://learn.microsoft.com/en-us/azure/cosmos-db/gen-ai/full-text-search#fuzzy-search

    Hope this helps. Do let us know if you have any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.