Databases 8 min read

SolrCloud Introduction and Spring Boot Example with Code

This article introduces SolrCloud, explains its relationship with Lucene and Solr, provides environment setup instructions for a CentOS 7.3 cluster, details Maven dependencies, configuration files, and a comprehensive Java implementation using Spring Boot, including repository interfaces, utility classes, and extensive unit tests for adding, querying, and deleting documents.

Architect's Tech Stack
Architect's Tech Stack
Architect's Tech Stack
SolrCloud Introduction and Spring Boot Example with Code

SolrCloud is a distributed search solution built on Lucene and Solr, allowing large indexes to be split across multiple nodes and merged for client queries.

The guide shows how to set up a SolrCloud cluster on CentOS 7.3 and provides a reference link for installation steps.

Required Maven dependencies are added to the pom.xml file, including spring-boot-starter-data-solr and spring-data-jpa .

A Spring configuration class enables Solr repositories and creates a CloudSolrClient bean using the Zookeeper host defined in application.properties ( spring.data.solr.zk-host=node1:2181,node2:2181,node3:2181 ).

The entity class @SolrDocument(solrCoreName="test_collection") defines fields id , ymqTitle , ymqUrl , and ymqContent with appropriate getters and setters.

The repository interface extends SolrCrudRepository<Ymq, String> and adds a custom query method annotated with @Query("ymqTitle:*?0*") to find documents by title.

A utility interface BaseSolr declares methods for adding, updating, deleting, and querying Solr documents, handling single beans, collections, and facet queries, and supporting pagination via RowBounds .

Implementation classes provide concrete logic for each operation, throwing IOException and SolrServerException as needed.

Unit tests, annotated with @RunWith(SpringRunner.class) and @SpringBootTest , demonstrate adding documents via the repository and CloudSolrClient , deleting by ID, and performing searches using both repository methods and the BaseSolr utility, with results printed as JSON strings.

Sample query results are shown for data JPA queries, SolrQuery syntax queries, and paginated queries, illustrating how to retrieve and display documents from the SolrCloud collection.

Contact information for the author and the GitHub repository ( https://github.com/souyunku/spring-boot-examples/tree/master/spring-boot-solr-cloud ) is provided at the end of the article.

JavaLuceneSpringBootSearchSolrCloudDistributedSearch
Architect's Tech Stack
Written by

Architect's Tech Stack

Java backend, microservices, distributed systems, containerized programming, and more.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.