A segment is a self-contained Lucene structure containing document data and inverted indexes. Elasticsearch first holds indexed documents in a shard’s in-memory buffer, then creates a segment during refresh; the segment becomes searchable after being written through the filesystem cache. section 5.1.2 section 3.2.4
A segment’s lifecycle follows a small operational pattern:
- A shard buffers incoming documents in heap memory until refresh, normally issued every second. section 5.1.2
- Refresh collects buffered documents into a new segment, making them available for search. section 5.1.2
- Lucene treats created segments as effectively immutable and avoids rewriting them for individual document changes. section 5.1.2
- After three segments form, Lucene merges them into a new segment and repeats the pattern. section 5.1.2
Inspect segments and their statistics
Use GET cars/_stats/segments to view segment statistics such as segment count, memory used, terms memory, stored-fields memory, and file sizes. Use GET cars/_segments for lower-level details, including each segment’s document count, deleted documents, disk space, and searchability. section 6.7.2
Figure 5.4 Mechanics of indexing documents
Trace how documents move from a shard’s in-memory buffer into refreshed segments and then toward durable storage. section 5.1.2

