DataImportHandler is not indexing mysql table in solr admin

喜欢而已 提交于 2019-12-06 03:29:06

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 your 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">

 <!-- this is the place where you map the columns of your result set
      to fields of the new solr document -->

        <field column="PRODUCT_ID" name="id" />
        <field column="NAME" name="name" />
        <field column="DESCRIPTION" name="description" />

    </entity>
  </document>
</dataConfig>

In your case there is one vital mapping you missed. product_id to id. Solr can autodetect mappings, if the column name and the name of the field in the schema are equal, as is written in the wiki

In the above example, there are mappings of fields to Solr fields. It is possible to totally avoid the field entries in entities if the names of the fields are same (case does not matter) as those in Solr schema.

But as said, in your situation that is not the case. product_id and id do differ. Since your id field is required 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!