liveBook · Manning

Segment

As explained in Elasticsearch in Action, Second Edition

A Lucene index segment is a self-contained, effectively immutable structure containing indexed documents, terms, and inverted-index data.

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

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains buffering, refresh, searchability, immutability, and three-segment merging, but does not detail segment file formats.
Examples
Uses one-second refreshes, three-segment merges, and Elasticsearch _stats/segments and _segments inspection APIs.
What it assumes
Assumes basic documents and shards, while introducing buffering, refresh, segment creation, and merging.
What you can do after
Diagnose segment counts, memory, disk usage, deleted documents, and searchability through Elasticsearch statistics APIs.
How it connects
Connects segments with shards, refresh, inverted indexes, filesystem cache, Lucene, and segment merging.

Also explained in

Compare how 2 books explain segment →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.