zh-hongda

搜索引擎-solrCloud数据导入

solrCloud数据导入。

solrCloud数据导入

使用的环境

solr5.3.1

tomcat8.0.28

zookeeper-3.5.1-alpha

目录结构如下:

solrCloud
├─service01
├─service02
├─service03
├─solr-5.3.1
├─solrhome01
├─solrhome02
├─solrhome03
├─solrhome04
├─tomcat01
├─tomcat02
├─tomcat03
├─tomcat04
└─启动zookeeper和solr服务器

  1. 准备好需要导入的文件。

  2. 将下列文件夹中jar包导入到,拷贝到solrCloud\tomcat01\webapps\solr\WEB-INF\lib中,且每一个tomcat都需要同样的操作。

    solr-5.3.1\dist

    solr-5.3.1\contrib\extraction\lib

  3. 在solrCloud\solrhome01\collection1\newConf\solrconfig.xml中加入如下配置。

<!--该操作的意义在于,在solr中加入dataImportHandler插件-->
<requestHandler name="/dataimport" class="solr.DataImportHandler">
    <lst name="defaults">
        <str name="config">data-config.xml</str>
    </lst>
</requestHandler>
  1. 在solrCloud\solrhome01\collection1\newConf\data-config中加入如下配置,这个文件夹需要自己创建。
<!--该操作的意义在于,配置实体-->
<dataConfig>
  <dataSource type="BinFileDataSource"/>
  <document>
    <entity name="file" processor="FileListEntityProcessor" dataSource="null"
            baseDir="D:\NLZ_HD\solr-server\data\CNNOJIT" fileName=".(doc)|(pdf)|(docx)|(txt)|(csv)|(json)|(xml)|(pptx)|(pptx)|(ppt)|(xls)|(xlsx)"
            rootEntity="false">

      <field column="file" name="id"/>
      <entity name="pdf" processor="TikaEntityProcessor"
              url="${file.fileAbsolutePath}" format="text">

        <field column="Author" name="file_author" meta="true"/>
        <field column="text" name="file_text"/>

      </entity>
    </entity>
  </document>
</dataConfig>
  1. 在solrCloud\solrhome01\collection1\newConf\schema.xml中添加如下配置。
<!--该操作的意义在于,配置`data-config`需要的域-->
<!--自定义field开始-->
    <field name="file_text" type="text_ik_Synonym" indexed="true" stored="true"  multiValued="false"/>
    <field name="file_author" type="string" indexed="true" stored="true" multiValued="false"/>
    <field name="file_keyWord" type="text_ik_Synonym" indexed="true" stored="true" multiValued="true"/>
<!--自定义field结束  -->
  1. 由于修改了配置文件,所以需要更新配置文件

    #此处直接上传了同名的配置文件覆盖之前的配置文件
    zkcli.bat -zkhost 127.0.0.1:2181 -cmd upconfig -confname new_config -confdir D:\NLZ_HD\solrCloud\solrhome01\collection1\newConf