Apache Lucene Reference

This section documents the current Apache Lucene 10.x line — Lucene 10 requires Java 21 — as published at the Apache Lucene documentation and Javadoc, which is the reference these pages are written and verified against. No specific patch version is pinned; examples target lucene-core 10.x and the companion modules. Some areas (the Panama foreign-memory / Vector API internals, codec file-format internals, and the nightly benchmark harness) are linked, not documented in depth.

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production, as Lucene iterates quickly.

This section’s bibliography lists the reference material consulted while preparing these pages.

Welcome to the Apache Lucene reference. Apache Lucene is an embedded, in-process Java search library — not a server: you add lucene-core to a JVM application, build an index on a local Directory of immutable segments, and open a searcher over it in the same process. Elasticsearch, OpenSearch and Apache Solr are all servers wrapped around this same library; everything they do for text analysis, the inverted index, query evaluation and scoring is Lucene underneath. This section documents the current Lucene 10.x line as a Java-developer reference — the index model and storage, the indexing chain, text analysis, the Query API and parsers, points / BKD range search, BM25 and custom scoring, collectors and concurrent search, kNN vector search, faceting, highlighting, suggesters, grouping and joins, near-real-time search and performance tuning — written and verified against the Apache Lucene documentation and Javadoc.

If you are new to Lucene, read Getting Started first, then Architecture & Data Flow and Documents & Fields, followed by Query Parsers and Core Queries. Everything after that builds on those foundations.

For the search servers built on Lucene and how they compare, see the sibling Elasticsearch Reference and Apache Solr Reference, and this section’s own Lucene vs. Solr vs. Elasticsearch vs. OpenSearch. For the relational and document-database baselines this section contrasts with, see the sibling SQL Reference, MongoDB Reference and Couchbase Reference, which the Lucene pages cross-link rather than restate. For where a dedicated search library or engine fits alongside a primary store, see Choosing the Right Database.

What’s covered

Getting started

  • Getting Started — what Lucene is as an embedded in-process Java search library, adding lucene-core and the companion modules to a Maven or Gradle build, and a first end-to-end index-and-search round-trip.

  • Architecture & Data Flow — the index model (a Directory of immutable segments, generations and commits, the pluggable codec) and the indexing and search class chains that write to and read from it.

Storing & indexing

  • Directories & Storage — the Directory abstraction and its implementations (MMapDirectory, NIOFSDirectory, ByteBuffersDirectory), write.lock and LockFactory, IndexInput prefetch and ReadAdvice, and why Lucene storage leans on the OS page cache rather than the JVM heap.

  • Documents & Fields — the Document as a schema-free ordered list of Field objects, the modern field types and what each one enables, FieldType and IndexOptions, and a capability matrix for picking searchable vs. stored vs. sortable vs. range vs. vector.

  • Indexing & Merge Policies — how IndexWriter adds, updates, soft-deletes and commits documents, the IndexWriterConfig knobs that shape a segment, and why and how Lucene merges segments (TieredMergePolicy and the other policies, plus the merge schedulers).

  • Near-Real-Time Search — making uncommitted IndexWriter changes searchable with DirectoryReader.open(writer) and openIfChanged, managing readers with SearcherManager and ControlledRealTimeReopenThread, stable paging with SearcherLifetimeManager, and the reference-counting rules that keep it safe.

Text analysis

  • Analysis Pipeline — how an Analyzer turns text into terms: the CharFilter / Tokenizer / TokenFilter chain, the TokenStream lifecycle and stream reuse, and the attribute API that carries term text, positions and offsets.

  • Built-in Analyzers & CustomAnalyzer — the ready-made analyzers in lucene-analysis-common (StandardAnalyzer, EnglishAnalyzer and the language set), PerFieldAnalyzerWrapper, and building an analyzer from factory names with CustomAnalyzer.builder().

  • Token Filters & Recipes — practical token-filter chains for folding, stop words, synonym graphs, stemming, autocomplete n-grams, shingles, word-delimiter splitting and payloads.

  • Language Analysis — the optional analysis modules for non-Latin scripts and language-specific matching (ICU, Kuromoji, Nori, SmartCN, Stempel, Morfologik, phonetic and OpenNLP).

Querying & scoring

  • Query Parsers — the classic QueryParser syntax and its pitfalls, SimpleQueryParser, the flexible StandardQueryParser framework, ComplexPhraseQueryParser, and when to skip parsing entirely.

  • Core Queries — the org.apache.lucene.search Query hierarchy (term, boolean, phrase, multi-term, range, wrapper and set queries), with construction examples and notes on QueryVisitor and rewriting.

  • Points & Range Queries — how Lucene indexes numeric and multi-dimensional values as points in a BKD tree, and the IntPoint / LongPoint / DoublePoint queries, IndexOrDocValuesQuery, doc-values skip lists, and the IntField / LongField convenience types.

  • Interval & Span Queries — positional and proximity matching with the modern Intervals / IntervalQuery API (ordered, unordered, maxgaps, containing, containedBy, before, after) and the legacy SpanQuery family it supersedes.

  • Filtering & Faceting — filtering with BooleanClause.Occur.FILTER, ConstantScoreQuery and TermInSetQuery cached by the searcher’s LRUQueryCache, and the lucene-facet module (FacetsConfig, taxonomy vs. SortedSetDocValues counting, range and value facets, drill-down / drill-sideways).

  • Scoring & Similarity — BM25Similarity as the default ranking model (its k1 and b parameters, field-length norms and SmallFloat quantisation), the alternative Similarity implementations, PerFieldSimilarityWrapper, and the Explanation API.

  • Function & Custom Scoring — reshaping relevance with FunctionScoreQuery and DoubleValuesSource, FeatureField relevance signals, the lucene-expressions module, and sorting by field, by script and by score.

  • Collectors & Concurrent Search — how Lucene gathers hits: the CollectorManager model that replaces bare Collector, running one query across an Executor, the total-hits threshold and TotalHits.Relation, early termination, and writing a custom CollectorManager.

  • Retrieving Results — turning search hits into data: the StoredFields API and selective loading with StoredFieldVisitor, reading doc values and term vectors, and paging with searchAfter against a stable searcher.

  • kNN Vector Search — dense-vector retrieval with KnnFloatVectorField and KnnByteVectorField, the HNSW graph and its quantised codec formats, KnnFloatVectorQuery with pre-filtering, exact kNN and hybrid lexical + vector search, and the Panama Vector API acceleration.

  • Spatial Search — LatLonPoint and LatLonShape in lucene-core, the prefix-tree and serialized strategies in lucene-spatial-extras, geo3d geometry on the ellipsoid in lucene-spatial3d, and WKT / GeoJSON parsing.

  • Highlighting, Suggesters & More — the lucene-highlighter UnifiedHighlighter and its offset-source requirement, the lucene-suggest Lookup and NRT completion APIs, spell checking, MoreLikeThis from lucene-queries, and the lucene-classification module.

  • Grouping & Joins — result grouping with the lucene-grouping module (GroupingSearch, first-pass / second-pass collectors, block grouping) and relating documents with the lucene-join module (query-time JoinUtil joins and index-time block joins).

  • Monitor / Reverse Search — reverse search with lucene-monitor: registering MonitorQuery objects in a Monitor and matching incoming documents against all of them, with a Presearcher to scale to large query sets and CandidateMatcher variants for the match detail you need.

Operations & tooling

  • Performance Tuning — tuning for indexing throughput (RAM buffer sizing, one shared IndexWriter, deferred merges, forceMerge for a static index, parallel build with addIndexes) and for search latency (a reused IndexSearcher via SearcherManager, reader warming, the page-cache / heap split for MMapDirectory, the LRUQueryCache, DocValues sorting, capped hit counting), plus how to measure with the nightly benchmarks.

  • Testing, Tools & Modules — the lucene-test-framework (LuceneTestCase, BaseTokenStreamTestCase, newDirectory, RandomIndexWriter, randomized and Nightly testing), CheckIndex for corruption, IndexUpgrader with lucene-backward-codecs, the Luke index browser, and the benchmark, replicator and misc tool modules — plus a one-line map of every Lucene module.

  • Lucene vs. Solr vs. Elasticsearch vs. OpenSearch — how the embedded Lucene library compares with the three search servers built on it on deployment model, clustering, API style, licensing and operational weight, with a decision list for choosing one.

Cheat sheet

  • Cheat Sheet (PDF) — a single-page, printable summary of everything in this section, with a downloadable PDF.

Bibliography

  • the Apache Lucene site and its per-release Javadoc — the source every page in this section is written and verified against. See in particular the Javadoc package overviews (core/index, core/document, core/analysis, core/search, core/store, codecs) and the module pages (analysis-common, analysis-icu / -kuromoji / -nori / -smartcn / -stempel / -morfologik / -phonetic / -opennlp, queryparser, queries, facet, highlighter, suggest, join, grouping, expressions, classification, monitor, spatial-extras, spatial3d, replicator, luke, benchmark, misc, test-framework, backward-codecs, demo), plus Changes.html, MIGRATE.md and the system-requirements page. Current release: Lucene 10.x; Lucene 10 requires Java 21.

  • McCandless, Michael; Hatcher, Erik; Gospodnetić, Otis. Lucene in Action, Second Edition. Manning Publications, 2010. ISBN 9781933988177. Consulted as part of the bibliography for this section; its code targets Lucene 3.0.x and predates the Lucene 4 field-type / codec / DocValues rewrite, points / BKD (6.x), BM25 as the default similarity (6.x), the Filter removal, CustomAnalyzer, the Intervals API, UnifiedHighlighter, FunctionScoreQuery, CollectorManager / concurrent search, soft deletes, the Monitor module, kNN / HNSW vector search (9.x) and the Java-21 / Panama MMapDirectory (10.x). Where it and the official documentation disagree, the official documentation is authoritative and the difference is noted; none of its content is the primary or main reference for this section. Publisher page: manning.com/books/lucene-in-action-second-edition.

  • The book above is a consulted bibliographic reference only. It is not the primary or main reference for this section, and where it and the official Apache Lucene documentation disagree, the official documentation is authoritative and the difference is noted.