Web / Apache Lucene Interview questions
Explain the internal working of Lucene's point-based fields (BKD tree) for range queries?
Since Lucene 6, numeric and spatial range queries (IntPoint, LongPoint, DoublePoint, and spatial fields) are backed by a BKD tree (a block K-dimensional tree), which replaced the older trie-based NumericField encoding used previously.
A BKD tree recursively partitions points into a balanced tree structure, splitting on alternating dimensions, with leaf nodes holding blocks of points stored in sorted order. A range query descends the tree, quickly pruning entire subtrees that fall completely outside the query range, and only fully scans leaf blocks that partially overlap the range boundary.
This gives range queries logarithmic-ish traversal cost that scales well even for high-cardinality numeric fields and multi-dimensional data like latitude/longitude pairs, which is exactly what made BKD trees a better general-purpose fit than the older trie encoding - especially for multi-dimensional range and spatial queries where a simple trie doesn't naturally generalize.
More Related questions...