Share via

Having time out issue while querying COSMOS DB with filter

2026-05-25T11:43:46.9+00:00

Hi I hava a COSMOS Database with mongodb core with around 5.5 Lac records. The query is giving consistent timeouts when using a filter long with vector Search. We have configured to use DISKANN for vector search. The Filter query is a simple check like {"field_name":"String Value"}. I have not created any text index in the database.

Azure Cosmos DB
Azure Cosmos DB

An Azure NoSQL database service for app development.

0 comments No comments

Answer accepted by question author

Amira Bedhiafi 42,846 Reputation points MVP Volunteer Moderator
2026-05-25T12:05:18.3866667+00:00

Hello !

Thank you for posting on MS Learn Q&A.

I think your filter field is not indexed because a text index is not needed for {"field_name": "String Value"}. You need a normal MongoDB ascending index on the filter field in addition to the DiskANN vector index.

For exact match filtering with Cosmos DB MongoDB vCore vector search you need to create a normal index on the filter field. DiskANN only indexes the vector path and it does not automatically optimize metadata filters.

db.yourCollection.createIndex({ field_name: 1 })

Then keep the filter inside the $search.cosmosSearch.filter section:

db.yourCollection.aggregate([
  {
    "$search": {
      "cosmosSearch": {
        "path": "contentVector",
        "vector": queryVector,
        "k": 10,
        "lSearch": 100,
        "filter": {
          "field_name": { "$eq": "String Value" }
        }
      }
    }
  }
])

DiskANN filtering creates both the vector index and a separate index on the filter field for example is_open: 1 specifically so filtered vector search can be optimized.

https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/vector-search

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.