Setup Solr 6.x with MySQL

Solr

 

This article is a step by step tutorial on how to get Solr 6.x configured with MySQL and run your first data import.

Download Solr and create your first collection

1. Download latest 6.x Solr release from http://lucene.apache.org/solr/
2. Open the folder and start Solr instance and create your first core

./bin/solr start
./bin/solr create -c collection1

3. Open http://localhost:8983/solr/ and check that collection has been created.

Edit solrconfig.xml

4. Go to ./server/solr/collection1/conf/solrconfig.xml and edit solrconfig.xml, add the following before existing <lib… statements:

<lib dir="${solr.install.dir:../../../..}/contrib/dataimporthandler/lib" regex=".*\.jar" />
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-.*\.jar" />

And the following to section <!– Request Handlers

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">solr-data-config.xml</str>
</lst>
</requestHandler>

Save and close the file.

Create solr-data-config file

5. Create a file called ./server/solr/collection1/conf/solr-data-config.xml with the following contents

<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/db_name"
user="root"
password="password"/>
<document>
<entity name="entity_name"
query="SELECT * FROM TABLE_NAME">
<field column="id" name="id"/>
<field column="name" name="name"/>
</entity>
</document>
</dataConfig>

Make sure you replace username and password, and corresponding query for the entity. Describe each field as needed.

Connect with Mysql and restart Solr

6. You will need to add the following. Download JDBC driver for MySQL from http://dev.mysql.com/downloads/connector/j/.

Copy file from the downloaded archive ‘mysql-connector-java-*.jar’ to the folder ‘./contrib/dataimporthandler/lib’ in the folder where Solr was installed. Create ‘lib’ folder if needed.

7. Restart Solr

./bin/solr restart

8. Go to http://localhost:8983/solr/, find your collection and add your fields as needed to the schema (select Schema in collection menu).

9. Do a full import by selecting Dataimport from the menu, execute it.

You should now have a working Solr instance. If your query is empty, and no documents indexed, please inspect Logging section, it should give you some hints about what is happening.

See examples of exceptional work we have done for our clients

View case studies

GET IN TOUCH

Contact us to discuss your next project:

+44 (0) 20 8090 0828
info@atomate.net

Contact us now