Important Notice: DIH Removed in Solr 9+
The Data Import Handler (DIH) module has been removed from Apache Solr starting with version 9. If you are using Solr 9 or later, DIH is no longer available and you will need to use alternative data ingestion methods such as the Solr REST API, SolrJ, or tools like Apache NiFi.
Note that Solr versions 3, 4, 5, 6, 7, and 8 have all reached End of Life (EoL) per the Apache Software Foundation. However, Opensolr is the only hosting provider that still fully supports all of those legacy versions for customers who rely on them — including full DIH support.
What Is the Data Import Handler?
The Solr Data Import Handler (DIH) allows you to import data directly from a relational database (such as MySQL, PostgreSQL, or Oracle) into your Solr index. Instead of writing your own import scripts, you configure an XML file that tells Solr how to connect to your database and which SQL query to run.
Step 1: Edit Your db-data-config.xml
In your Opensolr Control Panel, navigate to your index management area. You will find the option to edit the db-data-config.xml file. This file defines your database connection and the query used to fetch data.
Here is an example configuration:
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://YOUR_DB_HOST/YOUR_DB_NAME"
user="your-username"
password="your-password" />
<document>
<entity name="id"
query="SELECT id, name, description FROM your_table">
</entity>
</document>
</dataConfig>
Step 2: Ensure Your Schema Matches
The fields returned by your SQL query must be defined in your schema.xml. For example, if your query returns id, name, and description, your schema.xml must have corresponding field definitions:
<field name="id" type="string" indexed="true" stored="true" required="true" />
<field name="name" type="text_general" indexed="true" stored="true" />
<field name="description" type="text_general" indexed="true" stored="true" />
Step 3: Run the Import
Once configured, you can trigger a full import from the Opensolr Control Panel or via the DIH endpoint:
curl "https://YOUR_SOLR_HOST/solr/YOUR_INDEX/dataimport?command=full-import"
Video Tutorial
Watch this step-by-step demonstration of configuring the MySQL Data Import Handler on Opensolr:
Alternatives for Solr 9+
Since DIH is not available in Solr 9 and later, consider these alternatives for importing data from MySQL:
- Solr REST API — Send JSON or XML documents directly via HTTP POST to the
/updateendpoint. - CSV Import — Export your MySQL data as CSV and upload it to Solr using the
/update/csvhandler. - Client Libraries — Use libraries like SolrJ (Java), Solarium (PHP), or pysolr (Python) to programmatically index data.
- Apache NiFi — A powerful data flow tool that can pull from MySQL and push to Solr.