SQL Server in Solr using Data Import Handler


MS SQL Server connector

Download Microsoft JDBC Driver 4.0 for SQL Server from: http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774

copy file ‘sqljdbc4.jar’ to ‘contrib/dataimporthandler/lib’


copy solrconfig.xml from an existing collection. Find my version of solrconfig.xml below in this gist.

edit solrconfig.xml by adding:

<lib dir="../../contrib/dataimporthandler/lib" regex=".*\.jar" />
<lib dir="../../dist/" regex="solr-dataimporthandler-.*\.jar" />

Make sure that ‘dist’ folder contains two files for data import handler:

  • solr-dataimporthandler-4.10.2.jar
  • solr-dataimporthandler-extras-4.10.2.jar

add these lines to solrconfig.xml:

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
    <str name="config">data-config.xml</str>

data-config.xml for SQL Server database

  <dataSource type="JdbcDataSource" 
    <entity name="product"  
      query="select id,name from products"
      deltaImportQuery="SELECT id,name from products WHERE id='${dih.delta.id}'"
      deltaQuery="SELECT id FROM products  WHERE updated_at > '${dih.last_index_time}'"
       <field column="id" name="id"/>
       <field column="name" name="name"/>       

Copy from: https://gist.github.com/maxivak/3e3ee1fca32f3949f052


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s