Composite Index

From Ilianko

← Back to DP-420 Terminology Reference

Category: Optimization

Summary: Index across multiple properties to support efficient multi-property filter/sort queries.

Overview

A composite index is an index defined across multiple properties (in a specified order and sort direction) to efficiently support queries that filter or sort on more than one property at once — such as an ORDER BY across two properties, or equality/range filters combined with a sort. Without an appropriate composite index, such queries may require more RUs or fail to use the index efficiently.

{
  "indexingMode": "consistent",
  "includedPaths": [
    {
      "path": "/*"
    }
  ],
  "excludedPaths": [
    {
      "path": "/_etag/?"
    }
  ],
  "compositeIndexes": [
    [
      {
        "path": "/category/?",
        "order": "ascending"
      },
      {
        "path": "/timestamp/?",
        "order": "descending"
      }
    ]
  ]
}

More Info & Links

DP-420 Style Practice Questions

Q1. When is a composite index particularly useful in Azure Cosmos DB?

  • A. When a query filters or sorts (ORDER BY) on multiple properties simultaneously
  • B. When a container has only one property in every document
  • C. When TTL is enabled
  • D. When using only point operations

Q2. What must be specified when defining a composite index?

  • A. The set of properties and their sort order (ascending/descending)
  • B. Only the partition key
  • C. The container's throughput mode
  • D. The consistency level

Answer Key

Answers are listed at the very end so you can attempt the questions first.

  • Q1 (Composite Index): A. When a query filters or sorts (ORDER BY) on multiple properties simultaneously — Composite indexes optimize queries that need efficient filtering or ordering across multiple properties at once.
  • Q2 (Composite Index): A. The set of properties and their sort order (ascending/descending) — A composite index definition specifies the ordered list of properties along with ascending/descending sort order for each.

DP-420: Designing and Implementing Cloud-Native Applications Using Microsoft Azure Cosmos DB — term detail page