DataImportHandler未在solr admin中索引mysql表

我正在尝试使用DataImportHandler在solr中索引mysql表,但似乎没有索引

数据配置文件

 <?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>

当我尝试在solr admin(http:// localhost:8080 / solr / dataimport?command = full-import)中建立索引时,我得到此响应

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

如果我搜索(http:// localhost:8080 / solr / select?q = *:*)之后,我得到0结果.

更新1:schema.xml

解决方法:

您只是错过了结果集中的列到文档字段的映射.您需要在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>

在您的情况下,您错过了一个重要的映射. product_id到id.如果列名和模式中字段的名称相等,那么Solr可以自动检测映射,如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.

但是正如您所说,情况并非如此. product_id和id确实有所不同.由于您的ID字段是必填字段,因此这些文档将不会进入索引.

可以找到更多信息in Solr’s Wiki about the DataImportHandlerin the reference guide.

上一篇:spring data solr入门


下一篇:php-我们如何监视SOLR数据获取速度?