本人也是刚接触solr,有些问题还请指导
最初我想同时导入两张表的数据到索引中,相关配置如下:
${solr_home}/db/conf/solrconfig.xml中:
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">/opt/solr/db/conf/db-data-config2.xml</str>
<str name="config">/opt/solr/db/conf/db-data-config.xml</str>
</lst>
</requestHandler>
两张表在同一个库中,由于schema.xml中需要配置<uniqueKey></uniqueKey>(uniqueKey必须配置)
一张表的主键名是goodsNo,另一张表merchantNo
所以我在schema.xml中添加如下配置:
.......
<field name="goodsNo" type="string" indexed="true" stored="true" />
<field name="merchantNo" type="string" indexed="true" stored="true" />
.........
<uniqueKey>goodsNo</uniqueKey>
<uniqueKey>merchantNo</uniqueKey>
....
但这样配置后,导入不成功,因为添加了uniqueKey之后,就表示这个字段是必填的。
而每次导入一张表的数据,会因为另外一张表的主键没有值而报错:
missing required field: merchantNo
后来我改为增量导入(分为2次导入2张表的数据,第一次导入使用full-import),关键配置如下:
db-data-config.xml(goods表,增量导入的数据)
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.1.200:3306/POINTS" user="points" password="points"/>
<document name="goods">
<entity name="goods" pk="goodsNo" query="select GOODS_NO,GOODS_NAME,CATALOG_ID,BRIEF,PIC_URL,SALE_PRICE,SALECOUNT,CREATE_DATE from goods where status='0'"
deltaImportQuery="select GOODS_NO,GOODS_NAME,CATALOG_ID,BRIEF,PIC_URL,SALE_PRICE,SALECOUNT,CREATE_DATE from goods where goods_no='${dataimporter.delta.goodsNo}'"
deltaQuery="select goods_no goodsNo from goods">
<!-- deltaQuery="select GOODS_NO,GOODS_NAME,CATALOG_ID,BRIEF,PIC_URL,SALE_PRICE,SALECOUNT,CREATE_DATE from goods where create_date > '${dataimporter.last_index_time}'" -->
<field column="GOODS_NO" name="goodsNo" />
<field column="GOODS_NAME" name="goodsName" />
<field column="CATALOG_ID" name="catalogId" />
<field column="BRIEF" name="brief" />
<field column="PIC_URL" name="picUrl" />
<field column="SALE_PRICE" name="salePrice" />
<field column="SALECOUNT" name="salecount" />
<field column="CREATE_DATE" name="createDate" />
</entity>
</document>
</dataConfig>