Solr is Converting Integers to Boolean: Why?

Recently I encountered an issue with Solr that caused me a few hours of grief. If you’re having the same issue, hopefully this will save you some time.

The Symptom:
You’re trying to import data from your database into Solr using the import functionality and the db-data-config.xml file. Values that are stored in your database as integers (1 or 0, for example) are showing up in Solr as the words “true” and “false”.

The Problem:
It turns out, if you store a value in your database as tinyint(1) and then try to import this value into Solr, Solr will convert your values into booleans. Solr will do this with zero regard for what you put as the field type in your Solr schema.xml file. Frustrating.

The Solution:
Open up your db-data-config.xml file, which is should be at solr-server-/solr/conf/db-data-config.xml

Add convertType=”true” to the dataSource tag, like so:

<dataSource type="" batchSize="" driver="" url="" user="" password="" convertType="true" />

Re-start Solr, re-try the import. Your integers should no longer show up as booleans.

EDIT: Thanks to Shalin Shekhar Mangar, who commented that the source of this issue lies in the JDBC specification. If you have the ability to do so on your platform, you can add tinyInt1isBit=false to the JDBC URL of your datasource to disable this and prevent this issue from happening.