Parameter Substitution / Macro Expansion

Macro Expansion is a new Solr 5.1 feature that does parameter substitution across all request parameters.

The macro expansion is done at the same point in time that default parameters are applied (i.e. when the request reaches the correct solr request handler). This means that request handler defaults, appends, and invariants configured for the handler may reference request parameters, and vice-versa.

Here’s a very simple example of parameterizing a range query in lucene/solr syntax:

q=price:[ ${low} TO ${high} ]

One can also specify default values:

q=price:[ ${low:0} TO ${high:100} ]

Substitutions can themselves contain further macro expansions:

&price_query=${price_field}:[ ${low} TO ${high} ] AND inStock:true

Even parameter names can have macro expansion applied. A simple example is faceting on a field to be specified via another parameter ff:


If you want to disable macro expansion, simply pass expandMacros=false as a request parameter.

We’ll be adding even more powerful macro expansion capabilities in the future, so drop by the solr-user mailing list to join the discussion!

Go to the Download page to try out the current functionality.