Luqum (LUcene QUery Manipolator) is a Python library that parses Lucene Query DSL strings, building an abstract syntax tree (AST) for inspection, analysis, and manipulation. It enables transforming Lucene DSL queries into native Elasticsearch JSON DSL. The library is currently at version 1.0.0 and sees releases as new features and maintenance updates are introduced, typically every few months. [1, 7, 11]
pip install luqumVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing a Lucene query string into an Abstract Syntax Tree (AST), resolving implicit operators, and converting the AST into an Elasticsearch Query DSL dictionary. It highlights core functionalities of `luqum` for query manipulation and transformation. [2, 3, 8]
Import `UnknownOperationResolver` from `luqum.utils` and apply it to your parsed AST, optionally specifying a `default_operation` (e.g., `AndOperation` from `luqum.tree`). [3, 8]
Manually set `node.head` and `node.tail` attributes on AST nodes when building trees programmatically to retain formatting information. The `auto_head_tail` utility can assist. [3, 8, 7]
Replace direct calls to `luqum.parser.parser.parse()` with `from luqum.thread import parse as thread_safe_parse` and then use `thread_safe_parse(query_string)` for thread-safe parsing. [6, 8]
Upgrade Python to 3.10+ or pin `luqum` to a version less than 0.14.0. [7]
Review and adapt code interacting with `luqum.naming` and `auto_name` according to the 0.11.0 release notes and updated documentation. [7]
Audit existing Elasticsearch queries generated by `luqum` for single-word matches and adjust expectations or logic if `match_phrase` behavior is strictly required (e.g., by explicitly modifying the AST before transformation). [7]
Run `pip install luqum` in your terminal to install the library.
Correct the Lucene query string to ensure all parentheses are matched and the expression is complete and valid.
Review the Lucene query string around the indicated position (`%d`) and correct any invalid characters, operators, or syntax.