I am trying to index the mysql table in solr using DataImportHandler, but it's seems not indexing
data-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/solr_tut"
user="root"
password=""/>
<document>
<entity name="product_id"
query="select product_id,name,description from products">
</entity>
</document>
</dataConfig>
solrconfig.xml
<lib dir="../../../contrib/dataimporthandler/lib/" regex=".*\.jar" />
<lib dir="../../../dist/" regex="solr-dataimporthandler-\d.*\.jar" />
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
When i try to index in solr admin(http://localhost:8080/solr/dataimport?command=full-import
) i am getting this response
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">19</int>
</lst>
<lst name="initArgs">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</lst>
<str name="command">full-import</str>
<str name="status">idle</str>
<str name="importResponse"/>
<lst name="statusMessages">
<str name="Total Requests made to DataSource">1</str>
<str name="Total Rows Fetched">4</str>
<str name="Total Documents Skipped">0</str>
<str name="Full Dump Started">2014-01-10 10:38:00</str>
<str name="">
Indexing completed. Added/Updated: 0 documents. Deleted 0 documents.
</str>
<str name="Committed">2014-01-10 10:38:00</str>
<str name="Total Documents Processed">0</str>
<str name="Time taken">0:0:0.33</str>
</lst>
<str name="WARNING">
This response format is experimental. It is likely to change in the future.
</str>
</response>
After if i search(http://localhost:8080/solr/select?q=*:*
), i am getting 0 result.
Update-1: schema.xml
You just missed the mapping of the columns in the result set to the documents fields. You need to do that within the
entity
element of yourdata-config.xml
.In your case there is one vital mapping you missed.
product_id
toid
. Solr can autodetect mappings, if the column name and the name of the field in the schema are equal, as is written in the wikiBut as said, in your situation that is not the case.
product_id
andid
do differ. Since yourid
field isrequired
those documents will not make it into the index.More information can be found in Solr's Wiki about the DataImportHandler or in the reference guide.