AZ-204 Practice Question: Connect to and consume Azure services and third-party services
A company uses Azure Cosmos DB for a global e-commerce platform. They need to query product inventory across multiple regions with low latency. The data is partitioned by product category. Some queries filter on category and price range. What indexing policy should be configured to optimize these queries?
⚠ Common exam trap
Many candidates confuse Cosmos DB indexing with SQL Server indexing, assuming a hash index on a single property is valid, when Cosmos DB only supports range (default) and spatial index types for single properties.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Create a composite index with (category, price).
A composite index on (category, price) allows Cosmos DB to efficiently satisfy queries that filter on both fields in a single index seek, avoiding a full scan. Composite indexes are designed for multi-property filters and sort orders, which directly matches the requirement to query by category and price range with low latency.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use a wildcard index for all properties.
Why it's wrong here
While a wildcard index can cover all properties, it significantly increases storage consumption and write RU/s for every document modification, as it indexes every possible path. For specific, high-volume queries targeting particular fields like `category` and `price`, a wildcard index is less efficient than a targeted index, as it doesn't provide the optimized lookup paths required for precise filtering or range operations on combined fields.
- ✓
Create a composite index with (category, price).
Why this is correct
Creating a composite index on `(category, price)` is the optimal solution for queries that filter, sort, or combine operations on both these fields efficiently. This index allows Azure Cosmos DB to quickly locate documents matching specific categories and price ranges, drastically reducing RU/s consumption and query latency. It provides a pre-sorted structure that accelerates multi-field filtering and `ORDER BY` clauses, making it ideal for e-commerce product searches.
- ✗
Add a hash index on category and a range index on price.
Why it's wrong here
Using separate hash and range indexes on `category` and `price` respectively does not provide the same query optimization benefits as a single composite index for multi-field queries. While individual lookups might be fast, the Cosmos DB query engine would still need to combine results from two separate index structures, which is less efficient for queries filtering or sorting on both fields simultaneously, potentially leading to higher RU consumption and latency.
- ✗
Enable spatial index on price.
Why it's wrong here
Enabling a spatial index on a numerical field like `price` is fundamentally incorrect and offers no performance advantage for typical e-commerce queries. Spatial indexes are specifically designed to optimize queries involving geospatial data types, such as points, polygons, and lines, for operations like 'within' or 'distance'. Applying it to a non-geospatial numeric field would only consume additional storage and write RU/s without providing any query acceleration.
Go deeper
Related to this question
About these practice questions
Courseiva writes every AZ-204 question from scratch — 881 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This AZ-204 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-204 exam.