Apache Solr: Setup and Basic Querying

Apache Solr is a fast open-source Java search server.
Solr provides a indexing, replication and load-balanced querying for your data, data may contains websites, databases and files.

Solr built based on Apache Lucene (http://lucene.apache.org/). Lucene is a high-performance, full-featured text search engine library written entirely in Java. It is a technology suitable for nearly any application that requires full-text search, especially cross-platform.

Download Solr

Apache provides a ready to use distribution for Solr, to download visit official site of Solr : https://lucene.apache.org/solr/ and click Download link.

For the demo i have used version 6.3.0 which is latest stable version at a time of writing of this blog. Download direct from http://redrockdigimark.com/apachemirror/lucene/solr/6.3.0/.

Distribution available in zip and tgz format.

  • zip: http://redrockdigimark.com/apachemirror/lucene/solr/6.3.0/solr-6.3.0.zip
  • tgz: http://redrockdigimark.com/apachemirror/lucene/solr/6.3.0/solr-6.3.0.tgz

Once downloaded extract it to your favorite location.
I have extracted it to E:\SOLR directory.

Let’s look into Filesystem.

Start Solr

To start a Solr Server follow steps below

  • Open command prompt
  • Change directory to E:\SOLR\solr-6.3.0\bin
  • Execute Command solr.cmd start

On successful execution of command it shows

Waiting up to 30 to see Solr running on port 8983
Started Solr server on port 8983. Happy searching!

Means everything goes fine and good to go.

Ready to GO!

We can check status of server using 2 methods
Command Based
Execute command below to check status of solr server.

E:\SOLR\solr-6.3.0\bin>solr.cmd status


Found Solr process 1212 running on port 8983

Web Based
You can hit below url in your favorite browser to see status.

Here it shows everything goes fine and that’s why we got this web page. It shows no core available and it required to create one. Next section will show you how to create a Core.

Create a Core

Here we are using command based methodology to create a Core.

E:\SOLR\solr-6.3.0\bin>solr.cmd create -c test


Copying configuration to new core instance directory:

Creating new core 'test' using command:


This command will create a necessary files into E:\SOLR\solr-6.3.0\server\solr directory shown in image below.

Let’s see web to check status of core “test”.

It shows created core and other details about it.
Thing which i want to highlight here is it shows numDocs is 0 means Solr contains 0 documents.

Indexing a file

I have created a sample xml file to be indexed.
File: employee.xml

        <field name="id">1</field>
        <field name="name">Employee_1</field>
        <field name="id">2</field>
        <field name="name">Employee_2</field>
        <field name="id">3</field>
        <field name="name">Employee_3</field>

Use command below to index content of above file.
Here i have placed my employee.xml at location E:\SOLR\employee.xml
and using posting tool(post.jar) which is provided by Solr and resides in distribution at location <SOLR_HOME>\example\exampledocs.


E:\SOLR\solr-6.3.0\example\exampledocs>java -Dc=test -jar post.jar E:\SOLR\employee.xml


SimplePostTool version 5.0.0
Posting files to [base] url http://localhost:8983/solr/test/update using content-type application/xml...
POSTing file employee.xml to [base]
1 files indexed.
COMMITting Solr index changes to http://localhost:8983/solr/test/update...
Time spent: 0:00:00.354

In previous section it shows value of numDocs and MaxDoc is 0 as we don’t have any document available, not we have 3 documents which you can verify using web.

Now it show numDocs is 3.

Basic Searching

Here we are using web based method to search on core.
To begin with search please select “test” from “Query Selector” and than click on “Query” to open a query browser, it open a query browser in right area.

Here we want to search a documents where value contains “Employee_1” so we added “Employee_1” in text-area labeled with “q” and hit “Execute Query” button.

Now it shows output in right pane.

You can use direct web url also for searching.


    "responseHeader": {
        "status": 0,
        "QTime": 0,
        "params": {
            "q": "Employee_1",
            "indent": "on",
            "wt": "json"
    "response": {
        "numFound": 1,
        "start": 0,
        "docs": [
                "id": "1",
                "name": [
                "_version_": 1552234017134215200

That’s it for basics.

Will have some good tutorials on querying, administration, performance, optimization, load balancing and integration with Spring and Java in upcoming post.

Share current post by copy: https://goo.gl/kYSqsa
Happy Learning!

Thanks, Yogesh P