Spring Data Solr

Installing and Configuring Apache Solr

In this article, I will explain how to install and configuring Apache Solr into your machine (either Linux or Windows). Currently, many organizations are using the Apache Solr as a search technology. The Apache Solr makes it easy for programmers to develop sophisticated, high-performance search applications with advanced features.

In the series of articles for the Spring Data Solr, this article also gives you exposure about the basic Solr architecture and features. In this article, we will be getting Solr up and running and also creating Solr collections with ingesting a variety of data sources into Solr collections.

Let’s install the Apache Solr into your machine.

System Requirements

There are following system requirements for installing the Apache Solr into your machine.

  • Apache Solr runs on Java 8 or greater.
  • CPU, disk and memory requirements are based on the many choices made in implementing Solr.

As you have seen that it is very few system requirement for the Apache Solr in the above section. Let’s download the Apache Solr latest version according to your machine.

Download Latest Release Version

Let’s download latest release of the Apache Solr from here. In this tutorial, I have downloaded and designed for Apache Solr 7.3. There are multiple archives available, you can download according to your machine.

Note: prior to the Solr 4.1 release, all distribution and artifact filenames contained an apache- prefix.

Installing and Configuring Apache Solr 7.3

Let’s unpack downloaded archive of the Apache Solr 7.3.

~$ unzip -q solr-7.3.1.zip

You can see about Solr’s directory layout into your machine as following diagram:

Solr has been installed into your machine by only changing your working directory to the sub directory where Solr was installed.

~$ cd solr-7.3.1/

After installing and configuring, let’s launch Solr in your machine.

Launch Solr

To launch Solr, run: bin/solr start on Unix or MacOS; and bin\solr.cmd start on Windows. As following screenshot:

Launch Solr in SolrCloud Mode

You can also launch two-node cluster of the Solr (both nodes on the same machine). Let’s use the following commands to launch Solr in SolrCloud Mode,

On Unix or MacOS

Use the following command to launch the Solr in SolrCloud mode in your Linux or MacOS machine.

bin/solr start -e cloud

On Windows

Use the following command to launch the Solr in SolrCloud mode in your Windows machine.

bin\solr.cmd start -e cloud

The above commands will run the Solr into interactive mode and asking to decide port number, collection name etc. You can provide this information at the run time. You can see that Solr is running by launching the Solr Admin UI in your web browser: http://localhost:8983/solr/ as following:

Let’s create collections in the Solr.

Creating Collections

You can use the following command to create collections in the Solr server.

bin\solr create -c Book

Let’s see the following diagram:

Similarly you can create some more collections such as Order, Product and verify them on the Solr Core Admin as following diagram:

After creating collections, let’s move to index these collections with Data.

Index the Solr Collections with Data

Solr includes the bin/post tool in order to facilitate indexing various types of documents easily. We’ll use this tool for the indexing examples below.

On Linux or MacOS

The data we will index is in the example/exampledocs directory. The documents are in a mix of document formats (JSON, CSV, etc.), and fortunately we can index them all at once:

solr-7.3.1:$ bin/post -c Book example/exampledocs/*

On Windows

Currently the bin/post tool does not have a comparable Windows script, but the underlying Java program invoked is available. You can see the D:\personal data\spring-data\solr-7.3.1\example\exampledocs directory contains post.jar, you can use it to post index to Solr server as following:

After indexing Solr Collections, let’s move to next section to basic searching functionality.

Basic Searching

Solr can be queried via REST clients, curl, wget, Chrome POSTMAN, etc., as well as via native clients available for many programming languages.

Let’s click on Query tab in the Solr Admin UI and it opens a query builder interface and click on search (Execute Query). As following:

In this article, we have explained how to install and configure the Apache Solr into your machine and posting some indexes as well. But you can learn more about the Solr functionalities form here.

I hope now you can create Solr server in your machine.

Thanks for learning with the Dineshonjava.

Previous
Next
Dinesh Rajput

Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies. It has a series of articles related to Java technologies. Dinesh has been a Spring enthusiast since 2008 and is a Pivotal Certified Spring Professional, an author of a book Spring 5 Design Pattern, and a blogger. He has more than 10 years of experience with different aspects of Spring and Java design and development. His core expertise lies in the latest version of Spring Framework, Spring Boot, Spring Security, creating REST APIs, Microservice Architecture, Reactive Pattern, Spring AOP, Design Patterns, Struts, Hibernate, Web Services, Spring Batch, Cassandra, MongoDB, and Web Application Design and Architecture. He is currently working as a technology manager at a leading product and web development company. He worked as a developer and tech lead at the Bennett, Coleman & Co. Ltd and was the first developer in his previous company, Paytm. Dinesh is passionate about the latest Java technologies and loves to write technical blogs related to it. He is a very active member of the Java and Spring community on different forums. When it comes to the Spring Framework and Java, Dinesh tops the list!

Share
Published by
Dinesh Rajput

Recent Posts

Strategy Design Patterns using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

2 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

2 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

2 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

2 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

2 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

2 years ago