Show Menu

Lucene Query Syntax Cheat Sheet by

Query examples for using Lucene Query Syntax
lucene

Keyboard Matching

Search for word "­foo­" in the title field
title: foo

Search for phrase "foo bar" in the title field
title: "foo bar"

Search for phrase "foo bar" in the title field AND the phrase "­quick fox" in the body field.
title­:"foo bar" AND body:"quick fox"

Search for either the phrase "foo bar" in the title field AND the phrase "­quick fox" in the body field, or the word "­fox­" in the title field.
(titl­e:"foo bar" AND body:"quick fox") OR title:fox

Search for word "­foo­" and not "­bar­" in the title field.
title:foo -title­:bar

Wildcard matching

Search for any word that starts with "­foo­" in the title field.
title­:foo*

Search for any word that starts with "­foo­" and ends with bar in the title field.
title­:fo­o*bar

Note that Lucene doesn't support using a symbol as the first character of a *search.
 

Proximity matching

Search for "foo bar" within 4 words from each other.
"foo bar"~4

Range Searches

Range Queries allow one to match documents whose field(s) values are between the lower and upper bound specified by the Range Query. Range Queries can be inclusive or exclusive of the upper and lower bounds. Sorting is done lexico­gra­phi­cally.
mod_d­ate­:[2­0020101 TO 20030101]

Boosts

Query-time boosts allow one to specify which terms/­clauses are "more import­ant­". The higher the boost factor, the more relevant the term will be, and therefore the higher the corres­ponding document scores.

A typical boosting technique is assigning higher boosts to title matches than to body content matches:
(titl­e:foo OR title:­bar­)^1.5 (body:foo OR body:bar)

Boolean Operators

To search for all transa­ctions except MySQL transa­ctions:
NOT type: mysql

To search for all MySQL SELECT queries with large attach­ments:
mysql.me­thod: SELECT AND mysql.s­ize: [10000 TO *]

Lucene also supports parent­heses to group sub queries.
To search for either INSERT or UPDATE MySQL queries with a respon­setime greater or equal with 30ms:
(mysq­l.m­ethod: INSERT OR mysql.m­ethod: UPDATE) AND respon­set­ime:[30 TO *]

Download the Lucene Query Syntax Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/sudhirdaruwala_lucene-query-syntax.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets