Quarkus Solr

Apache Solr is the blazing-fast, open source, multi-modal search platform built on the full-text, vector, and geospatial search capabilities of Apache Lucene. This extension provides integration with Solr, allowing you to easily add search capabilities to your Quarkus application.

It provides the following features:

  • Solr as a dev-service for local development

  • Provide SolrJ beans for interacting with Solr

  • Native compilation support

  • Integration with Quarkus observability stack (health, metrics, logging)

Installation

If you want to use this extension, you need to add the io.quarkiverse.solr:quarkus-solr extension first to your build file.

For instance, with Maven, add the following dependency to your POM file:

<dependency>
    <groupId>io.quarkiverse.solr</groupId>
    <artifactId>quarkus-solr</artifactId>
    <version>1.0.3</version>
</dependency>

Use SolrJ in your application

You can inject the SolrClient bean provided by the extension to interact with Solr. Each class will get its own instance of SolrClient (scope is @Dependent), so you can safely add custom configuration to it if needed. For example:

import org.apache.solr.client.solrj.SolrClient;

@ApplicationScoped
public class SolrService {
    @Inject
    SolrClient solrClient;

    public SolrDocumentList query(String query) throws SolrServerException, IOException {
        SolrQuery solrQuery = new SolrQuery();
        solrQuery.setQuery(query);
        return solrClient.query("collectionName", solrQuery).getResults();
    }
}

Check the SolrJ documentation for more details on how to use the SolrClient to Query and Index documents in Solr.

Dev Services for Solr

The extension provides a dev service for Solr. This allows you to easily run a Solr instance in a container during development.

By default, the dev service will start a Solr instance with a single collection named dummy. You can further customize the dev service

Observability

All interactions with Solr are logged at the DEBUG level, request and response details are logged at TRACE level. You can enable DEBUG logging for the io.quarkiverse.solr package to see the details of the interactions. If you add quarkus-smallrye-health or quarkus-micrometer-registry-prometheus to your application, a health check and metrics will be automatically provided for the Solr client.

Extension Configuration Reference

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

Type

Default

Is solr health check enabled

Environment variable: QUARKUS_SOLR_HEALTH_ENABLED

boolean

true

If DevServices has been explicitly enabled or disabled. DevServices is generally enabled by default, unless there is an existing configuration present.

When DevServices is enabled Quarkus will attempt to automatically configure and start a solr instance when running in Dev or Test mode and when Docker is running.

Environment variable: QUARKUS_SOLR_DEVSERVICES_ENABLED

boolean

true

The container image name to use, for container based DevServices providers.

If not set, the default solr image in the version of solrj will be used

Environment variable: QUARKUS_SOLR_DEVSERVICES_IMAGE_NAME

string

Optional fixed port the dev service will listen to.

If not defined, the port will be chosen randomly.

Environment variable: QUARKUS_SOLR_DEVSERVICES_PORT

int

The name of the collection to be created in Solr

If not defined, a collection names "dummy" will be created

Environment variable: QUARKUS_SOLR_DEVSERVICES_COLLECTION

string

Custom configuration to be used. Must be a directory on the classpath containing at least a solrconfig.xml

If not set, default configuration of Solr docker container is used

Environment variable: QUARKUS_SOLR_DEVSERVICES_CONFIGURATION

string

The value of the label attached to the started container. This property is used when shared is set to true. In this case, before starting a container, Dev Services looks for a container with the quarkus-dev-service-solr label set to the configured value. If found, it will use this container instead of starting a new one. Otherwise, it starts a new container with the quarkus-dev-service-solr label set to the specified value.

This property is used when you need multiple shared Solr instances.

Environment variable: QUARKUS_SOLR_DEVSERVICES_SERVICE_NAME

string

solr

Indicates if the instance managed by Quarkus Dev Services is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, Dev Services starts a new container.

The discovery uses the quarkus-dev-service-solr label. The value is configured using the service-name property.

Container sharing is only used in dev mode.

Environment variable: QUARKUS_SOLR_DEVSERVICES_SHARED

boolean

true

One or more Solr URLs, which the client then uses to send HTTP requests to Solr.

These URLS must point to the root Solr path (i.e. "/solr"). If multiple URLs are configured, it is assumed that Solr Cloud Mode is used and these URLs are used to fetch information about the layout and health of the Solr cluster.

If only one URL is defined, the URLs is used to send user-provided requests using org.apache.solr.client.solrj.impl.HttpJdkSolrClient HttpJdkSolrClient.

Environment variable: QUARKUS_SOLR_URL

list of string

required

Default collection to be used

Most SolrClient methods allow users to specify the collection or core they wish to query, etc. as a String parameter. However, continually specifying this parameter can become tedious, especially for users who always work with the same collection.

Users can avoid this pattern by specifying a "default" collection If specified SolrClients will use this default for making requests whenever a collection or core is needed (and no overriding value is specified)

Environment variable: QUARKUS_SOLR_DEFAULT_COLLECTION

string

Should HTTP 1.1 be used instead of HTTP/2?

If not set, HTTP/2 is used by default

Environment variable: QUARKUS_SOLR_HTTP1

boolean

false

Request timeout in milliseconds

If not set, idle timeout is used

Environment variable: QUARKUS_SOLR_REQUEST_TIMEOUT

long

Idle timeout in milliseconds

If not set, org.apache.solr.client.solrj.impl.SolrHttpConstants#DEFAULT_SO_TIMEOUT SolrJ’s default value is used

Environment variable: QUARKUS_SOLR_IDLE_TIMEOUT

long

Connection timeout in milliseconds

If not set, org.apache.solr.client.solrj.impl.SolrHttpConstants#DEFAULT_CONNECT_TIMEOUT SolrJ’s default value is used

Environment variable: QUARKUS_SOLR_CONNECTION_TIMEOUT

long

Should the client follow redirects?

If not set, redirect are not followed

Environment variable: QUARKUS_SOLR_FOLLOW_REDIRECTS

boolean

false

Maximal number of connections per host

If not set, org.apache.solr.client.solrj.impl.SolrHttpConstants#DEFAULT_MAXCONNECTIONS SolrJ’s default value is used

Environment variable: QUARKUS_SOLR_MAX_CONNECTIONS_PER_HOST

int

The username

Environment variable: QUARKUS_SOLR_BASIC_AUTH_USERNAME

string

required

The password

Environment variable: QUARKUS_SOLR_BASIC_AUTH_PASSWORD

string

required

The proxy host

Environment variable: QUARKUS_SOLR_PROXY_HOST

string

required

The proxy port

Environment variable: QUARKUS_SOLR_PROXY_PORT

int

0

Is this a socks4 proxy?

Environment variable: QUARKUS_SOLR_PROXY_SOCKS4

boolean

false

Is this proxy using HTTPS

Environment variable: QUARKUS_SOLR_PROXY_SECURE

boolean

false

Force SolrCloud mode

If set, it is assumed that Solr Cloud Mode is used even if only one url() is defined

Environment variable: QUARKUS_SOLR_CLOUD

boolean

false

Zookeeper client timeout in milliseconds

Only relevant if Solr Cloud Mode is used even. If not set, org.apache.solr.client.solrj.impl.SolrZkClientTimeout#DEFAULT_ZK_CLIENT_TIMEOUT SolrJ’s default value is used

Environment variable: QUARKUS_SOLR_ZK_CLIENT_TIMEOUT

int

Zookeeper connection timeout in milliseconds

Only relevant if Solr Cloud Mode is used. If not set, org.apache.solr.client.solrj.impl.SolrZkClientTimeout#DEFAULT_ZK_CONNECT_TIMEOUT SolrJ’s default value is used

Environment variable: QUARKUS_SOLR_ZK_CONNECT_TIMEOUT

int

Can Zookeepers ACL be used

Only relevant if Solr Cloud Mode is used. See documentation for details. If not set,SolrJ’s default value (true) is used.

Environment variable: QUARKUS_SOLR_CAN_USE_ZK_AC_LS

boolean

Cache ttl for cached objects in seconds

Only relevant if Solr Cloud Mode is used. If not set,SolrJ’s default value (60s) is used.

Environment variable: QUARKUS_SOLR_COLLECTION_CACHE_TTL

int

Number of parallel collection state refresh operations to run in parallel

Only relevant if Solr Cloud Mode is used. If not set,SolrJ’s default value (5) is used.

Environment variable: QUARKUS_SOLR_PARALLEL_CACHE_REFRESHES

int

Time to wait to re-fetch the state after getting the same state version from Zookeeper in milliseconds

Only relevant if Solr Cloud Mode is used. If not set,SolrJ’s default value (3000) is used.

Environment variable: QUARKUS_SOLR_RETRY_EXPIRY_TIME

long

Should shard updates be sent in parallel

Only relevant if Solr Cloud Mode is used. When an UpdateRequest affects multiple shards, CloudSolrClient splits it up and sends a request to each affected shard. This setting chooses whether those sub-requests are sent serially or in parallel. If not set,SolrJ’s default value ('true') is used.

Environment variable: QUARKUS_SOLR_PARALLEL_UPDATES

boolean