Spring Data Solr

Installing and Configuring Apache Solr

<p>In this article&comma; I will explain how to install and configuring Apache Solr into your machine &lpar;either Linux or Windows&rpar;&period; Currently&comma; many organizations are using the Apache Solr as a search technology&period; The Apache Solr makes it easy for programmers to develop sophisticated&comma; high-performance search applications with advanced features&period;<&sol;p>&NewLine;<p>In the <strong><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-data-solr-tutorial&sol;">series of articles for the Spring Data Solr<&sol;a><&sol;strong>&comma; this article also gives you exposure about the basic Solr architecture and features&period; In this article&comma; we will be getting Solr up and running and also creating Solr collections with ingesting a variety of data sources into Solr collections&period;<&sol;p>&NewLine;<div align&equals;"center"><iframe style&equals;"width&colon; 120px&semi; height&colon; 240px&semi;" src&equals;"&sol;&sol;ws-in&period;amazon-adsystem&period;com&sol;widgets&sol;q&quest;ServiceVersion&equals;20070822&amp&semi;OneJS&equals;1&amp&semi;Operation&equals;GetAdHtml&amp&semi;MarketPlace&equals;IN&amp&semi;source&equals;ac&amp&semi;ref&equals;tf&lowbar;til&amp&semi;ad&lowbar;type&equals;product&lowbar;link&amp&semi;tracking&lowbar;id&equals;dineshonjav06-21&amp&semi;marketplace&equals;amazon&amp&semi;region&equals;IN&amp&semi;placement&equals;1787127567&amp&semi;asins&equals;1787127567&amp&semi;linkId&equals;a1e64f621b5e6128d8cb10e876eb1c48&amp&semi;show&lowbar;border&equals;true&amp&semi;link&lowbar;opens&lowbar;in&lowbar;new&lowbar;window&equals;true&amp&semi;price&lowbar;color&equals;333333&amp&semi;title&lowbar;color&equals;0066c0&amp&semi;bg&lowbar;color&equals;ffffff" frameborder&equals;"0" marginwidth&equals;"0" marginheight&equals;"0" scrolling&equals;"no" align&equals;"center"><span data-mce-type&equals;"bookmark" style&equals;"display&colon; inline-block&semi; width&colon; 0px&semi; overflow&colon; hidden&semi; line-height&colon; 0&semi;" class&equals;"mce&lowbar;SELRES&lowbar;start"><&sol;span><br &sol;>&NewLine;<&sol;iframe><&sol;div>&NewLine;<p>Let&&num;8217&semi;s install the Apache Solr into your machine&period;<&sol;p>&NewLine;<h2>System Requirements<&sol;h2>&NewLine;<p>There are following system requirements for installing the Apache Solr into your machine&period;<&sol;p>&NewLine;<ul>&NewLine;<li>Apache Solr runs on Java 8 or greater&period;<&sol;li>&NewLine;<li>CPU&comma; disk and memory requirements are based on the many choices made in implementing Solr&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<p>As you have seen that it is very few system requirement for the Apache Solr in the above section&period; Let&&num;8217&semi;s download the Apache Solr latest version according to your machine&period;<&sol;p>&NewLine;<h2>Download Latest Release Version<&sol;h2>&NewLine;<p>Let&&num;8217&semi;s download latest release of the Apache Solr from <a href&equals;"http&colon;&sol;&sol;lucene&period;apache&period;org&sol;solr&sol;downloads&period;html" target&equals;"&lowbar;blank" rel&equals;"noopener">here<&sol;a>&period; In this tutorial&comma; I have downloaded and designed for Apache Solr 7&period;3&period; There are multiple archives available&comma; you can download according to your machine&period;<&sol;p>&NewLine;<p><strong>Note&colon;<&sol;strong> <em>prior to the Solr 4&period;1 release&comma; all distribution and artifact filenames contained an apache- prefix&period;<&sol;em><&sol;p>&NewLine;<h2>Installing and Configuring Apache Solr 7&period;3<&sol;h2>&NewLine;<p>Let&&num;8217&semi;s unpack downloaded archive of the Apache Solr 7&period;3&period;<&sol;p>&NewLine;<p><em>~&dollar; unzip -q solr-7&period;3&period;1&period;zip<&sol;em><&sol;p>&NewLine;<p>You can see about Solr’s directory layout into your machine as following diagram&colon;<&sol;p>&NewLine;<p><img class&equals;"aligncenter wp-image-4159 size-full" src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2018&sol;06&sol;solr&period;png" alt&equals;"Configuring Apache Solr" width&equals;"577" height&equals;"321" &sol;><&sol;p>&NewLine;<p>Solr has been installed into your machine by only changing your working directory to the sub directory where Solr was installed&period;<&sol;p>&NewLine;<p><em>~&dollar; cd solr-7&period;3&period;1&sol;<&sol;em><&sol;p>&NewLine;<p>After installing and configuring&comma; let&&num;8217&semi;s launch Solr in your machine&period;<&sol;p>&NewLine;<h2>Launch Solr<&sol;h2>&NewLine;<p>To launch Solr&comma; run&colon; <em><strong>bin&sol;solr<&sol;strong> start<&sol;em> on <strong>Unix<&sol;strong> or <strong>MacOS<&sol;strong>&semi; and <strong><em>bin&bsol;solr&period;cmd start<&sol;em><&sol;strong> on <strong>Windows<&sol;strong>&period; As following screenshot&colon;<&sol;p>&NewLine;<p><img class&equals;"aligncenter size-full wp-image-4161" src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2018&sol;06&sol;launch-solr&period;png" alt&equals;"launch solr" width&equals;"483" height&equals;"70" &sol;><&sol;p>&NewLine;<h3>Launch Solr in SolrCloud Mode<&sol;h3>&NewLine;<p>You can also launch two-node cluster of the Solr &lpar;both nodes on the same machine&rpar;&period; Let&&num;8217&semi;s use the following commands to launch Solr in SolrCloud Mode&comma;<&sol;p>&NewLine;<h4>On Unix or MacOS<&sol;h4>&NewLine;<p>Use the following command to launch the Solr in SolrCloud mode in your Linux or MacOS machine&period;<&sol;p>&NewLine;<p><em>bin&sol;solr start -e cloud<&sol;em><&sol;p>&NewLine;<h4>On Windows<&sol;h4>&NewLine;<p>Use the following command to launch the Solr in SolrCloud mode in your Windows machine&period;<&sol;p>&NewLine;<p><em>bin&bsol;solr&period;cmd start -e cloud <&sol;em><&sol;p>&NewLine;<p>The above commands will run the Solr into interactive mode and asking to decide port number&comma; collection name etc&period; You can provide this information at the run time&period; You can see that Solr is running by launching the Solr Admin UI in your web browser&colon; <strong><a href&equals;"http&colon;&sol;&sol;localhost&colon;8983&sol;solr&sol;" target&equals;"&lowbar;blank" rel&equals;"noopener">http&colon;&sol;&sol;localhost&colon;8983&sol;solr&sol;<&sol;a><&sol;strong> as following&colon;<&sol;p>&NewLine;<p><img class&equals;"aligncenter size-full wp-image-4162" src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2018&sol;06&sol;running-solr&period;png" alt&equals;"running solr" width&equals;"1147" height&equals;"639" &sol;><&sol;p>&NewLine;<p>Let&&num;8217&semi;s create collections in the Solr&period;<&sol;p>&NewLine;<h2>Creating Collections<&sol;h2>&NewLine;<p>You can use the following command to create collections in the Solr server&period;<&sol;p>&NewLine;<p><em>bin&bsol;solr create -c Book<&sol;em><&sol;p>&NewLine;<p>Let&&num;8217&semi;s see the following diagram&colon;<&sol;p>&NewLine;<p><img class&equals;"aligncenter size-full wp-image-4163" src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2018&sol;06&sol;creating-collection&period;png" alt&equals;"creating collection" width&equals;"642" height&equals;"95" &sol;><&sol;p>&NewLine;<p>Similarly you can create some more collections such as Order&comma; Product and verify them on the Solr Core Admin as following diagram&colon;<&sol;p>&NewLine;<p><img class&equals;"aligncenter size-full wp-image-4164" src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2018&sol;06&sol;solr-collections&period;png" alt&equals;"solr collections" width&equals;"684" height&equals;"474" &sol;><&sol;p>&NewLine;<p>After creating collections&comma; let&&num;8217&semi;s move to index these collections with Data&period;<&sol;p>&NewLine;<h2>Index the Solr Collections with Data<&sol;h2>&NewLine;<p>Solr includes the bin&sol;post tool in order to facilitate indexing various types of documents easily&period; We’ll use this tool for the indexing examples below&period;<&sol;p>&NewLine;<h3>On Linux or MacOS<&sol;h3>&NewLine;<p>The data we will index is in the <em>example&sol;exampledocs<&sol;em> directory&period; The documents are in a mix of document formats &lpar;JSON&comma; CSV&comma; etc&period;&rpar;&comma; and fortunately we can index them all at once&colon;<&sol;p>&NewLine;<p><em>solr-7&period;3&period;1&colon;&dollar; bin&sol;post -c Book example&sol;exampledocs&sol;&ast;<&sol;em><&sol;p>&NewLine;<h3>On Windows<&sol;h3>&NewLine;<p>Currently the bin&sol;post tool does not have a comparable Windows script&comma; but the underlying Java program invoked is available&period; You can see the <em>D&colon;&bsol;personal data&bsol;spring-data&bsol;solr-7&period;3&period;1&bsol;example&bsol;exampledocs<&sol;em> directory contains post&period;jar&comma; you can use it to post index to Solr server as following&colon;<&sol;p>&NewLine;<p><img class&equals;"aligncenter wp-image-4165 size-full" src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2018&sol;06&sol;post-index&period;png" alt&equals;"post-index" width&equals;"700" height&equals;"107" &sol;><&sol;p>&NewLine;<p>After indexing Solr Collections&comma; let&&num;8217&semi;s move to next section to basic searching functionality&period;<&sol;p>&NewLine;<h2>Basic Searching<&sol;h2>&NewLine;<p>Solr can be queried via REST clients&comma; curl&comma; wget&comma; Chrome POSTMAN&comma; etc&period;&comma; as well as via native clients available for many programming languages&period;<&sol;p>&NewLine;<p>Let&&num;8217&semi;s click on Query tab in the Solr Admin UI and it opens a query builder interface and click on search &lpar;<strong>Execute Query<&sol;strong>&rpar;&period; As following&colon;<&sol;p>&NewLine;<p><img class&equals;"aligncenter size-full wp-image-4166" src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2018&sol;06&sol;searching&period;png" alt&equals;"solr searching" width&equals;"826" height&equals;"640" &sol;><&sol;p>&NewLine;<p>In this article&comma; we have explained how to install and configure the Apache Solr into your machine and posting some indexes as well&period; But you can learn more about the Solr functionalities form <a href&equals;"https&colon;&sol;&sol;lucene&period;apache&period;org&sol;solr&sol;guide&sol;7&lowbar;3&sol;solr-tutorial&period;html&num;tutorial-searching" target&equals;"&lowbar;blank" rel&equals;"noopener">here<&sol;a>&period;<&sol;p>&NewLine;<p>I hope now you can create Solr server in your machine&period;<&sol;p>&NewLine;<p>Thanks for learning with the <strong>Dineshonjava<&sol;strong>&period;<&sol;p>&NewLine;<div align&equals;"center"><iframe style&equals;"width&colon; 120px&semi; height&colon; 240px&semi;" src&equals;"&sol;&sol;ws-in&period;amazon-adsystem&period;com&sol;widgets&sol;q&quest;ServiceVersion&equals;20070822&amp&semi;OneJS&equals;1&amp&semi;Operation&equals;GetAdHtml&amp&semi;MarketPlace&equals;IN&amp&semi;source&equals;ac&amp&semi;ref&equals;qf&lowbar;sp&lowbar;asin&lowbar;til&amp&semi;ad&lowbar;type&equals;product&lowbar;link&amp&semi;tracking&lowbar;id&equals;dineshonjav06-21&amp&semi;marketplace&equals;amazon&amp&semi;region&equals;IN&amp&semi;placement&equals;1788299450&amp&semi;asins&equals;1788299450&amp&semi;linkId&equals;05b0146b0a85f4472697901e353dc276&amp&semi;show&lowbar;border&equals;true&amp&semi;link&lowbar;opens&lowbar;in&lowbar;new&lowbar;window&equals;true&amp&semi;price&lowbar;color&equals;333333&amp&semi;title&lowbar;color&equals;0066c0&amp&semi;bg&lowbar;color&equals;ffffff" frameborder&equals;"0" marginwidth&equals;"0" marginheight&equals;"0" scrolling&equals;"no"><br &sol;>&NewLine;<&sol;iframe><&sol;div>&NewLine;<div class&equals;"wp-post-navigation"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-pre"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-data-solr-tutorial&sol;">Previous<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-next"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-data-solr-configuration-using-spring-boot&sol;">Next<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;<&sol;div>&NewLine;<script type&equals;"text&sol;javascript">&NewLine;jQuery&lpar;document&rpar;&period;ready&lpar;function&lpar;&dollar;&rpar; &lbrace;&NewLine; &dollar;&period;post&lpar;'https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-admin&sol;admin-ajax&period;php'&comma; &lbrace;action&colon; 'mts&lowbar;view&lowbar;count'&comma; id&colon; '4158'&rcub;&rpar;&semi;&NewLine;&rcub;&rpar;&semi;&NewLine;<&sol;script>

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…

4 years ago

Decorator Pattern using Lambda

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

4 years ago

Delegating pattern using lambda

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

4 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;…

4 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

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

4 years ago

Scheduler @Scheduled Annotation Spring Boot

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

4 years ago