How to crawl a database on Solr without DIH - DIH alternative

This tutorial is based on Datafari 5.2, but the same procedure can be applied to more recent versions.

Starting from Solr 9, Solr does not contain anymore the Data Import Handler (DIH) package anymore. Yet it had a large users base, who are now looking for alternatives.

One of the main goals of DIH was to index databases easily into Solr.

In this page, we explain how to do it with Datafari Community Edition, the open source version of Datafari Enterprise Search. Thanks to several years of work, Datafari integrates seamlessly much more than what you will need to replace DIH, but we focus here on how to just replace DIH for a scenario with Solr. Out of the box and focusing on our DIH replacement scenario, Datafari 5.2 contains :

  • Apache ManifoldCF which is a framework of connectors (ManifoldCF is coded in Java and the output connection to Solr is configured out of the box into Datafari in SolrCloud mode so it is a smart client to index very quickly millions of documents into Solr)

  • Solr 8 to index data crawled from MCF

  • and the webapp Datafari with a user interface to search into the data (as a bonus, since it is not needed in the DIH replacement scenario)

There are three main steps :

  1. Download and install Datafari

  2. (optional - not needed for PostgreSQL) Add the JDBC driver that corresponds to your database (we do not have the right to include it in Datafari due to licence issues for MariaDB or MySQL for example) unless you are crawling a PostgreSQL database, in which case the JDBC driver is already included
    NB : The next version of Datafari (5.3) will include by defaut the JDBC driver for Microsoft SQL server and Oracle server.

  3. Create your crawl job

Right after these steps, you can begin to search into your data !

Let’s explain these steps :

For this tutorial, we use two instances on Scaleway :

  • GPS1 8x86 64 bit 32 Go RAM, 300 Go NVME with Debian 11

  • IP Datafari server : 51.158.69.126

  • IP MySQL server : 163.172.184.196

We will install Datafari on one instance, and a MySQL server 8 on the other one. Note that the installation of MySQL and the ingestion of a dataset into it are out of scope of this tutorial, and as such they are detailed in an annex.

1. Download and install Datafari

  • Connect into SSH to your server

  • Download latest stable version of Datafari :

    wget https://www.datafari.com/files/debian/datafari.deb
  • To install the dependencies of Datafari, download our convenient script to install them automatically :

    wget https://www.datafari.com/files/scripts_init_datafari/init_server_datafari_5_debian_10_plus.sh
  • Now execute the init script :

    source init_server_datafari_5_debian_10_plus.sh
  • Install Datafari :

  • init Datafari

And Voilà! Datafari is installed and functional. You can connect to https://$IP_OF_YOUR_DATAFARI_SERVER/datafariui

In our example : https://51.158.69.126/datafariui

For more information see this page : https://datafari.atlassian.net/wiki/spaces/DATAFARI/pages/1878753289

2. Install the JDBC driver into Datafari

In our example, we want to crawl a database into MySQL version 8.0.29.

We download the JDBC driver from Maven repository. The latest stable version is MySQL connector/J 8.0.29 : https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.29/mysql-connector-java-8.0.29.jar

  • Edit the file /opt/datafari/mcf/mcf_home/options.env.unix

Add the path to the new lib in the -cp parameter line :

The entire file (into Datafari 5.2) is this one :

For more information, see this page : https://datafari.atlassian.net/wiki/spaces/DATAFARI/pages/4947978

  • Restart Datafari - You have 2 options to do it :

    • Option 1 - Via the Datafari admin UI : Go to the main server of Datafari, then click on Services Administration and Restart.

    • Option 2 - By restarting Datafari via SSH :

For more information about restarting Datafari, see this page : https://datafari.atlassian.net/wiki/spaces/DATAFARI/pages/111903130

The final step is to configure the crawling job.

3. Configure the job

Go to the admin Datafari UI then go to Connectors → Data Crawler Simplified mode and select Create Database job.

You will need to fill in all the mandatory parameters to configure the job.

To get some information about the different fields see this page :

In our example, we crawl a dump of Wikipedia pages.

This is the structure :

And some data :

The configuration is this one :

  • Database type : MySQL

  • Database host : 163.172.184.196

  • Database name : wiki

  • user : root

  • Password : admin

  • Seeding query :

  • Version query

  • Data query

  • Source name : db

  • Repository name : msqylrepo

  • Start he job once created : check the box

  • Finally click on Save button

Then you can check if all is ok in your MCF : https://$IP_OF_YOUR_DATAFARI_SERVER/datafari-mcf-crawler-ui/

In our example : https://51.158.69.126/datafari-mcf-crawler-ui/

Depending on the number of rows in your database, the job will be first in ‘starting up’ mode to get all the ids of the documents to crawl. Only then will the “real” act of crawling start, and the job will be in “running” mode.

If you need to modify your job, simply edit it then relaunch the job.

Finally go to Datafari and search your data (optional, you do not need DatafariUI, you can do as you were doing before when you were combining DIH and Solr) :

Go to https://$IP_OF_DATAFARI_SERVER/datafariui

In our example : https://51.158.69.126/datafariui

You have a complete search solution in alternative to DIH, based on Apache ManifoldCF and Apache Solr.

Annexes

We detail here the steps we did to install MySQL server into the Scaleway instance.

  • Connect into SSH into the instance

  • Get MySQL Server 8 :

  • Check if MySQL is well started :

  • Get the SQL dump of English Wikipedia pages :

  • Uncompress it :

  • Create the database and change encoding :

  • Import the data into the database :

  • Change the configuration into MySQL to allow remote connection, to do so edit the file /etc/mysql/mysql.conf.d/mysqld.cnf :

And add this line at the end of the file :

ie here we allow any IP to connect to the MySQL database, it is just for demo purpose here !

  • Create a new user into the database :

In this example, the name of the user is datafari and the password is admin. We allow datafari user to connect to MySQL database from the location of our Datafari server : 51.158.69.126. We granted all privileges to datafari user, once again it is just for demo purpose.