An Azure NoSQL database service for app development.
Hi Vinod Pal,
Thanks for sharing the details—querying nested arrays with ARRAY_CONTAINS can indeed get expensive if the index isn’t tuned exactly to your data shape. To better recommend an indexing policy or query pattern, could you share a bit more information?
Follow-up questions:
- Can you post a small example of one of your documents (especially the items[] array), including its partition key path?
- What does your current indexing policy look like? Are you using the default “include all” policy, or have you overridden any include/exclude paths?
- What’s your partition key, and are you issuing a cross-partition query or targeting a single logical partition?
- How many elements do you typically have in items[]? Any idea of its average and maximum cardinality?
- Could you share the exact SQL query you’re running and the RU charge reported in the query metrics?
- From the query metrics, how many of the RUs are coming from “IndexLookup” vs. “DocumentLoad”?
- Have you tried adding a composite index on the array path or excluding other properties to reduce indexing overhead?
- Are you on provisioned or serverless (autoscale) throughput?
With those details, we can:
- Suggest a tailored indexing policy (for example, explicitly including the /items/* path or a composite index on /items/* plus your filter property).
- Recommend query rewrites or pagination strategies that limit document scans.
- Point you to best practices for indexing arrays in Cosmos DB.
Reference docs:
- Pricing model in Azure Cosmos DB https://docs.microsoft.com/azure/cosmos-db/how-pricing-works
- Optimize request cost in Azure Cosmos DB https://docs.microsoft.com/azure/cosmos-db/optimize-cost-reads-writes
- Plan and manage costs for Azure Cosmos DB https://docs.microsoft.com/azure/cosmos-db/plan-manage-costs age-costs