The Data Import Handler pulls rows straight out of a relational database into your index. You describe the connection and the query in one XML file, and Solr does the rest.
01 · Edit db-data-config.xml
In your index management area you will find the db-data-config.xml file. It holds the database connection and the query that fetches your rows:
<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>
02 · Match your schema to the query
Every column the query returns has to exist as a field in schema.xml:
<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" />
03 · Run the import
From the control panel, or straight against the endpoint:
curl "https://YOUR_SOLR_HOST/solr/YOUR_INDEX/dataimport?command=full-import"
Configuring the MySQL Data Import Handler on Opensolr.
04 · Alternatives on Solr 9 and later
The Solr REST API
POST your documents as JSON or XML to the /update endpoint. The most direct replacement.
CSV import
Export the table and load it through /update/csv. See importing CSV data.
A client library
SolrJ for Java, Solarium for PHP, pysolr for Python: read from the database and index in the same script.
Apache NiFi
A data flow tool that can pull from MySQL and push to Solr on a schedule, without you writing the glue.