When I was trying to connect solr with database to index the documents directly i was getting different exceptions. I searched on web and found that there were many people who were facing the same type of issues. Finally after trying different approaches i got success in connecting solr to mysql database.
For connecting solr to database there are two jar plugins needed. One is solr-dataimporthandler-...jar and other one is mysql-connector-java-...jar e.g. solr-dataimporthandler-extras-5.1.0.jar & mysql-connector-java-5.1.18-bin.jar. First one is used import the data from database and second one is used to connect the solr to mysql database. You can find first one already present in solr repository on location “…/solr-5.1.0/dist/”. But you have to add the mysql connector yourself.You can download the connector from here .
After download the connector jar, you need to place it in same dist folder. (You can place it anywhere and update the path of this file in solrconfig.xml but for the purpose of this post i am posting it in the same dist folder.)
Now you have to mention the location of these two jar files in solrconfig.xml . For this you have to add these two lines under the config tag of solrconfig.xml.
In solrconfig.xml you need to declare the config file location which holds the database connection settings and query. In my case i am naming it as data-config.xml . You can define this in solrconfig.xml using:
Please check the final solrconfig.xml :
Now you have to create a file data-config.xml and define the connection settings of database there.
Please mention the database_name , user and password accordingly. If you are not hosting mysql on port 3306 then put the url accordingly.
You can use the queries accoring to your schema.For more inforamtion on it please go through official wiki .
For your convenience i am posting the my schema.xml and core.properties files too.
Directory structure of core
Seems like i have posted the complete core. You shouldn’t get any problem while connecting solr to mysql database now. In case you get any problem.Please let me know through comments. I will try to help you.
Now to importing data to solr you can use this command or trigger full-import through solr UI.