Logit.io
lucene banner
← Back to blog
8/16/2024 · 2 min read

Lucene Query Syntax Cheat Sheet

Eleanor Bennett
Eleanor Bennett
Growth Marketing Lead at Logit.io

Last updated 7/27/2026

Resources

Lucene is an open-source full-text search library written in Java, used to add search functionality to applications and websites. It is known for its efficiency and flexibility, commonly utilized in Elasticsearch and Kibana for complex search operations.

Contents

Need to search production logs? Try hosted OpenSearch on Logit.io — see log management pricing.

Start Free Trial

Unlock complete visibility with hosted ELK, Grafana, and Prometheus-backed Observability

Start Free Trial

Basic Concepts

  • Indexing: Lucene uses an inverted index, which maps terms to the documents they appear in.
  • Documents and Fields: The primary units of search and indexing in Lucene. A document contains multiple fields, each with a unique name.

Query Syntax

Basic Queries

  • Term Query: Searches for documents containing the exact term.

  • Boolean Queries: Combine multiple queries using operators:

    • AND: Requires both terms to be present.
    • OR: Requires at least one of the terms to be present.
    • NOT: Excludes documents containing the term following the NOT operator.
  • Phrase Query: Searches for an exact phrase.

  • Wildcard Query: Uses ? for a single character and * for multiple characters.

Advanced Queries

  • Range Query: Searches for documents within a range of values.
  • Fuzzy Query: Searches for terms similar to the specified term.
  • Proximity Query: Searches for terms within a specified distance from each other.

Field-Specific Queries

  • Field Queries: Targets specific fields within documents.
  • Nested Queries: Groups sub-queries using parentheses.

Special Characters

Certain characters need to be escaped when used in queries: +, -, &, |, !, (, ), {, }, [, ], ^, ", ~, *, ?, :, \.

Practical Examples

  • Search for "Lucene" in the title field:

    • title:Lucene
  • Search for documents containing "error" but not "warning":

    • error -warning

lucenequery copy

This cheat sheet covers the essential Lucene queries and functions to help you get the most out of your search operations. Keep this guide handy for quick reference and to enhance your querying skills. Have we missed something? Feel free to email ebennett@logit.io with your suggestions or questions.

If you enjoyed this cheat sheet, why not check out our Loki cheat sheet or our PromQL cheat sheet next?

Get the latest Elastic Stack & logging resources when you subscribe

Want to see this in action?
Start a free trial and connect logs to your alert workflows.