搭建solr服务器之配置批量导入数据库中的数据

使用dataimport插件批量导入数据。

第一步:把dataimport插件依赖的jar包添加到solrcore(collection1\lib)中    -- E:\repository\solrHome\collection1\lib目录下

 

还需要mysql的数据库驱动。

第二步:配置solrconfig.xml文件,添加一个requestHandler(请求处理器)。

E:\repository\solrHome\collection1\conf

 <requestHandler name="/dataimport"

class="org.apache.solr.handler.dataimport.DataImportHandler">

    <lst name="defaults">

      <str name="config">data-config.xml</str>

     </lst>

  </requestHandler> 

第三步:创建一个data-config.xml,保存到collection1\conf\目录下

E:\repository\solrHome\collection1\conf

<?xml version="1.0" encoding="UTF-8" ?>  

<dataConfig>   

<dataSource type="JdbcDataSource"   

  driver="com.mysql.jdbc.Driver"   

  url="jdbc:mysql://localhost:3306/lucene"     --引入的数据库 lucene

  user="root"   

  password="root"/>   

<document>   

<entity name="product" query="SELECT pid,name,catalog_name,price,description,picture FROM products ">

 <field column="pid" name="id"/>

 <field column="name" name="product_name"/>

 <field column="catalog_name" name="product_catalog_name"/>

 <field column="price" name="product_price"/>

 <field column="description" name="product_description"/>

 <field column="picture" name="product_picture"/>

</entity>   

</document>   

 

</dataConfig>

第四步:设置业务系统Field

由于data-config.xml  数据配置文件中,配置的域与E:\repository\solrHome\collection1\conf目录下的schema.xml无法形成映射。所以在schema.xml中配置业务系统的域

<!--product  设置业务系统Field-->
   <field name="product_name" type="text_ik" indexed="true" stored="true"/>
   <field name="product_price"  type="float" indexed="true" stored="true"/>
   <field name="product_description" type="text_ik" indexed="true" stored="false" />
   <field name="product_picture" type="string" indexed="false" stored="true" />
   <field name="product_catalog_name" type="string" indexed="true" stored="true" />

 

<!-- 根据关键词搜索 -->
    <field name="product_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/>

<!-- 拷贝域   当你发送关键词 通过名字、描述都不正确时,把名字、描述都拷贝到指定的product_keywords里

这里配置的关键词默认搜索 product_keywords,就可以搜名字和描述的组合查询

-->
    <copyField source="product_name" dest="product_keywords"/>
    <copyField source="product_description" dest="product_keywords"/>

第五步:重启tomcat

 

第五步:点击“execute”按钮导入数据

到入数据前会先清空索引库,然后再导入。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hi,all

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值