Elasticsearch indexes documents by first storing them in an in-memory buffer and transaction log on each node. After a soft-commit interval, documents are written to file system cache in a new segment. A hard commit then synchronizes these segments to disk, clears the memory buffers and transaction log. New documents continue to be indexed in this way, with merging occasionally combining segments to reduce space and improve search performance.