Get a DemoStart Free TrialSign In

Resources

1 min read

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

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 [email protected] 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

© 2024 Logit.io Ltd, All rights reserved.