当前位置:   article > 正文

05、向solr导入数据库中数据_solr8 配置 data-config managed-schema

solr8 配置 data-config managed-schema

1、jar包配置

将连接数据库的jar包和solr\dist下的dataimporthandler架包复制到solr\server\solr-webapp\webapp\WEB-INF\lib下

2、创建data-config.xml文件

​ 在goods(core名)/conf文件夹下创建mysql-db文件夹,然后在mysql-db文件夹中创建data-config.xml文件,文件中添加如下内容

 <?xml version="1.0" encoding="utf-8" ?>
   <dataConfig>
       <dataSource type="JdbcDataSource"
        driver="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/sc"
        user="root"
        password="root"
       />
       <document>
       <!--sql配置-->
           <entity name="goods" query="select goods_id,goods_name,sales_price,goods_img,cid from goods">
                  <!--column为数据库中列名,name为属性名-->
                  <field column="goods_id" name="id" />
                  <field column="goods_name" name="goodsName" />
                  <field column="sales_price" name="salesPrice" />
                  <field column="goods_img" name="goodsImg" /> 
                  <field column="cid" name="cid" />
           </entity>
   
       </document>
   </dataConfig>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

3、 添加document中的字段

在managed-schema.xml文件中添加

<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<!-- docValues are enabled by default for long type so we don't need to index the version field  -->
<field name="_version_" type="plong" indexed="false" stored="false"/>
<field name="_root_" type="string" indexed="true" stored="false" docValues="false" />
<!--字段名与第二步相对应,text_ik为查找的字段-->
<field name="goodsName" type="text_ik" indexed="true" stored="true"  multiValued="false" />
<field name="salesPrice" type="plong" indexed="true" stored="true"  multiValued="false" />
<field name="goodsImg" type="string" indexed="true" stored="true"  multiValued="false" />
<field name="cid" type="string" indexed="true" stored="true"  multiValued="false" />
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

注意: id,version,root 不能删除,text 不需要 可以删除

4、导入data-config.xml文件

在solrconfig.xml文件中添加

 <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
      <str name="config">mysql-db/data-config.xml</str>
    </lst>
  </requestHandler>
  • 1
  • 2
  • 3
  • 4
  • 5

5、 重启solr

重启命令:solr restart -p 8983

6、导入数据

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/789027
推荐阅读
相关标签
  

闽ICP备14008679号