Solr Query Syntax

The default Solr query syntax used to search an index uses a superset of the Lucene query syntax.

Trying a basic query

The main query for a solr search is specified via the q parameter. Standard Solr query syntax is the default (registered as the “lucene” query parser).

If this is new to you, please check out the Solr Tutorial.

Adding debug=query to your request will allow you to see how Solr is parsing your query.

{
  "responseHeader":{
    "status":0,
    "QTime":0,
    "params":{
      "q":"hello",
      "debug":"query"}},
  "response":{"numFound":0,"start":0,"docs":[]
  },
  "debug":{
    "rawquerystring":"hello",
    "querystring":"hello",
    "parsedquery":"text:hello",
    "parsedquery_toString":"text:hello",
    "QParser":"LuceneQParser"}}

The response section will normally contain the top ranking documents for the query. In this example, no documents matched the query.
In the debug section, one can see how the query was parsed, and the fact that text was used as the default field to search.

Basic Queries

A “term” query is a single word query in a single field that must match exactly.
In this example text is the field name, and hello is the word we are going to match in that field.

text:hello

Phrase Query

A phrase query matches multiple terms (words) in sequence.

text:"yonik seeley"

This query will match text containing Yonik Seeley but will not match Yonik C Seeley or Seeley Yonik.

Internally, a phrase query is created when the fieldType produces multiple terms for the given value. For the example above, the fieldType splits on whitespace and lowercases the result, and we get two terms… [yonik, seeley]. If our fieldType had been string, a single term of yonik seeley would have been produced since string fields do not change values in any way.

Boosted Query

Any query clause can be boosted with the ^ operator. The boost is multiplied into the normal score for the clause and will affect it’s importance relative to other clauses.

Boosted Query Examples:

text:heliosearch^10 text:rocks
text:(heliosearch^10 rocks)
(inStock:true AND text:heliosearch)^123.45 text:hi

Constant Score Query

(Heliosearch only)
A ConstantScoreQuery is like a boosted query, but it produces the same score for every document that matches the query. The score produced is equal to the query boost. The ^= operator is used to turn any query clause into a ConstantScoreQuery.

Constant Score Query Examples:

+color:blue^=1 text:shoes
(inStock:true text:heliosearch)^=100 native code faceting

Filter Query

(Heliosearch only)
A filter query retrieves a set of documents matching a query from the filter cache. Since scores are not cached, all documents that match the filter produce the same score (0 by default). Cached filters will be extremely fast when they are used again in another query.

Filter Query Example:

description:HDTV OR filter(+promotion:tv +promotion_date:[NOW/DAY-7DAYS TO NOW/DAY+1DAY])

The power of the filter() syntax is that it may be used anywhere within a lucene/solr query syntax. Normal fq support is limited to top-level conjunctions. However when normal top-level fq filter caching can be used, that form is preferred.

Query Comments

(Heliosearch only)
One can embed comments in a query using C-style comments surrounded with /* */. Comments can be nested.

Query Comments Example:

description:HDTV /* TODO: +promotion:tv +promotion_date:[NOW/DAY-7DAYS TO NOW/DAY+1DAY] */