Web / Apache Lucene Interview questions
What is the difference between DocValues and stored fields for sorting or faceting?
Both can technically hold the same data, but they're organized completely differently on disk, and that difference matters a lot for sorting and faceting workloads specifically.
| Stored fields | DocValues |
| Row-oriented: all fields for one document stored together. | Column-oriented: all values for one field stored together. |
| Optimized for "give me everything about document X". | Optimized for "compare this one field across many documents". |
| Poor fit for sorting/faceting at scale. | Purpose-built for fast sorting, faceting, and aggregations. |
Sorting by a stored field would require decompressing and reading a scattered row-store entry per document; DocValues instead lay values out contiguously per field, so scanning or comparing them across millions of documents is dramatically cheaper. The practical rule: use DocValues fields for anything you'll sort, facet, or aggregate on, and reserve stored fields for values you need to display back verbatim.
More Related questions...