how to index data in solr from database automatically

Romi picture Romi · Jun 24, 2011 · Viewed 13.9k times · Source

I have MySql database for my application. i implemented solr search and used dataimporthandler(DIH)to index data from database into solr. my question is: is there any way that if database gets updated then my solr indexes automatically gets update for new data added in the database. . It means i need not to run index process manually every time data base tables changes.If yes then please tell me how can i achieve this.

Answer

Rakesh Sankar picture Rakesh Sankar · Jun 24, 2011

I don't think there is a possibility in Solr which lets you index the data when any updates happens to DB.

But there could be possibilities like, with the help of Triggers - there is a possibility to run an external application from triggers.

Write a CRON to trigger PHP script which does reading from the DB and indexing it in Solr. Write a trigger (which calls this script) for CRUD operation and dump it into DB, so, whenever something happens to DB, this trigger will call the above script and indexing could happen.

Please see:

Invoking a PHP script from a MySQL trigger

Automatic Scheduling:

Please see this post How can I Schedule data imports in Solr for more information on scheduling. The second answer, explains how to import using Cron.