Quick Set-Up Guide for Applications in Solr-5

Solr is a standalone enterprise search server from the Apache Lucene project. It supports documents using JSON, XML, CSV or binary over HTTP. It provides the REST-based query and supports various formats like JSON, XML, CSV and binary.

Solr offers an easy-to-use platform on which applications can be installed and run in a few minutes.

Installing Solr

Prerequisites

Java 7 or greater should be installed.

Downloading Solr-5

Download and unpack the latest Solr release from the Apache download mirrors.

Unzipping

Begin by unzipping the Solr. Below is an example with a shell in UNIX:

/:$ ls solr*
solr-5.1.0.zip
/:$ unzip -q solr-5.1.0.zip
/:$ cd solr-5.1.0/

Starting Solr

To launch Solr, run the “bin/solr” start code below:

/solr-5.1.0:$ bin/solr start

Waiting to see Solr listening on port 8983 [/]  
Started Solr server on port 8983 (pid=3208). Happy searching with SOLR!

Solr runs by adding the Solr Admin UI in the main web browser. This is the main starting point for administering Solr.

Solr-5

To start Solr with a different port, use the code below:

/solr-5.1.0:$ bin/solr start –p 8984

Indexing Data

Once the Solr server is running, data must be inputted. Solr supports indexing-structured content in a variety of incoming formats such as XML, JSON, and CSV, with SolrXML being the predominant format. The XML files can be posted using the “bin/post” command, which will send the HTTP Post request to Solr as well as update the endpoint.

The “bin/post” command can be used to post the contents to Solr, which are automatically indexed by Solr.

bin/post -c [coreName] [path]
e.g. bin/post -c gettingstarted example/exampledocs/*.xml

More Indexing Techniques include:

  • Import records from a database using the Data Import Handler (DIH)
  • Use SolrJ from JVM-based languages or other Solr clients to programmatically create documents to send to Solr
  • Use the Admin UI core-specifics Documents tab to paste in a document to be indexed, or select Document Builder from the Document Type drop down to build a document one field at a time. Click on the Submit Document button below the form to index the document

Core

Create one or multiple cores to allow for individualized indexing and searching. With the help of the core, data can be indexed with different structures in the same server.

The following command can be used to create a core, which can later be used to add documents and start searching:

bin/solr create -c <name>

A property file inside the core folder (i.e. /server/<corename>/core.properties) gets created automatically with the above command. This file contains the following properties:

PropertyDescription
nameThe name of the SoleCore
configThe configuration file name for a given core. If not defined, the default value for this field is “solrconfig.xml”
schemaThe schema file name for a given core. If not defined, the default value for this field is “schema.xml”
dataDirThe data directory of the core where indexes are stored. The path of dataDir is relative to the path of core’s instanceDir. If not defined, the default value is “data”
configSetThe name of a defined Configuration Set, if desired, to use to configure the core
propertiesThe name of the properties file for this core. The value can be an absolute pathname or a path relative to the value of instanceDir
transientIf true, the core can be unloaded if Solr reaches the transientCacheSize. The default value, if not deined, is “false.” Cores are unloaded in the order of the least recently used to the most recently used
loadOnStartupIf true, the default, if it is not specified, will cause the core to load when Solr starts
coreNodeNameUsed only in SolrCloud, this is a unique identifier for the node hosting this replica.  By default, a coreNodeName is generated automatically, but setting this attribute explicitly allows the user to manually assign a new core to replace an existing replica. For example: when replacing a machine that has had a hardware failure by restoring from backups on a new machine that has a new hostname or port
ulogDirThe absolute or relative directory for the update log for this core (SolrCloud)
shardThe shard assigned to this core (SolrCloud)
collectionThe name of the collection of which this core is a part (SolrCloud)
rolesFuture parameter for SolrCloud, or a way for users to mark nodes for their own use
Solr-5

Adding “Documents”

Use the Solr “bin/post” command below to add the documents mentioned above

bin/post -c <corename> <path>

Adding “Documents” from Admin Console

Post the documents to Solr through the following interface, which provides the options to post the content based on content type, along with other properties.

Solr-5

Updating Data

The schema.xml file specifies the uniqueKey field called “id”. Whenever a command to add a document with the same value is entered, the server automatically replaces the data with the newly entered data. This can be seen by looking for the values of numDocs and Max document in the core specific overview section of the Solr Admin UI.

Deleting Data

Delete data by posting a “delete” command to the update URL and specifying the value of the document’s unique key field, or a query that matches multiple documents. The command given below allows for a specific document to be deleted:

bin/post -c <corename> -d "<delete><id>id1</id></delete>"

Searching

Queries can be made to Solr using either REST clients, cURL, wget, Chrome, or POSTMAN; queries can also be made using native clients available in many programming languages.

The Solr Admin UI includes a query builder interface located in the “Getting Started” query tab. If the Execute Query button is clicked without anything in the form being changed, 10 documents in the JSON format will be provided (*:* in the q param matches all documents):

Solr-5

To use cURL, give the same URL in quotes on the curl command line:

curl "http://localhost:8983/solr/gettingstarted/select?q=*%3A*&wt=json&indent=true"

To search for a term, give it as the ‘q’ param value in the core-specific Solr Admin UI Query section, and replace *:* with the term to find (ex. “name:james”).

Shutdown

The following command can be used to stop the Solr server:

bin/solr stop -all ;

Solr-5 Resources

For more information on Solr, use the following resources:

Sumit Nagpal

Sumit Nagpal

Sumit Nagpal has spent the last year and a half working as a Senior Software Engineer with 3Pillar Global. He has completed a SCJP1.6 certification and has a total of 4 years of programming experience in Java technologies like Servlets, JSPs, J2EE, EJB, Struts, Spring, Hibernate, Web Services, and JAXB, among others. He also has experience in the media advertisement domain working with large-scale clients to create different products.

3 Responses to “Quick Set-Up Guide for Applications in Solr-5”
  1. Rahul on

    Hi sumit tnx for this awesome guide . you have a idea how to import core form (solr 4) to solr 5 with out losing any data.

    Reply
  2. Anusha Hegde on

    Can you tell me more about the suggest feature? I use solr 5.3

    Reply
  3. Girish Rawat on

    Simple, straight forward, precise and well documented.

    Thanks Sumit!!

    Reply
Leave a Reply

Related Posts

Costovation – Giving Your Customers Exactly What They ... On this episode of The Innovation Engine podcast, we delve into “cost-ovation,” or innovation that gives your customers exactly what they want – and n...
AI & Machine Learning Will See You Now, and Other Takea... A 3Pillar team and I spent a few days in Santa Clara recently for the 12th annual Health 2.0 Conference. As usual, we spent some time after the confer...
DevSecOps – The Latest Trends in Application Security ... I spent a very rewarding couple of days at DevSecCon in Boston recently. The conference focused on DevSecOps, which is a catch-all phrase for addressi...
Designing the Future & the Future of Work – The I... Martin Wezowski, Chief Designer and Futurist at SAP, shares his thoughts on designing the future and the future of work on this episode of The Innovat...
Selecting The Minimum Viable Toolset for Product Managers Recently I was attending a machine learning conference and during a break, found myself deep in conversation with fellow product managers. As is typic...