DataImportHandler 未在 solr admin 中索引 mysql 表

2024-04-30

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

数据配置.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>

当我尝试在 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: 模式.xml http://pastebin.com/p8LUqNie


您刚刚错过了结果集中的列到文档字段的映射。您需要在entity你的元素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 to id。如果模式中的列名称和字段名称相等,Solr 可以自动检测映射,如 wiki 中所述

在上面的示例中,存在字段到 Solr 字段的映射。如果字段名称与 Solr 模式中的字段名称相同(不区分大小写),则可以完全避免实体中的字段条目。

但正如您所说,您的情况并非如此。product_id and id确实有所不同。自从你的id场是required这些文档不会进入索引。

更多信息可以找到在 Solr 的 Wiki 中有关 DataImportHandler 的内容 http://wiki.apache.org/solr/DataImportHandler#Configuration_in_data-config.xml or 在参考指南中 https://cwiki.apache.org/confluence/display/solr/Uploading+Structured+Data+Store+Data+with+the+Data+Import+Handler.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

DataImportHandler 未在 solr admin 中索引 mysql 表 的相关文章

随机推荐