博客信息

使用DIH将Mysql数据库中数据批量导入solr5.5.3

发布时间:『 2017-01-14 22:30』  博客类别:Solr/ES  阅读(1685) 评论(0)

第一步:创建一个配置Mysql数据源的XML文件db-data-config.xml放在和solrconfig.xml同目录下,内容:

<dataConfig>
    <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/dmpreport" user="root" password="root" batchSize="-1"/>
    <document name="report">
        <entity name="dmpreport" pk="device_id_md5" transformer="HTMLStripTransformer" query="select device_id_md5,device_id,device_type,update_time1 from t_device_info">
                <field column="device_id_md5" name="id" />
                <entity name="tags" query="select reverse(substring_index(reverse(substring_index(tags1,',',id)),',',1)) as tag from t_device_info,t_int where id <= 1+(length(tags1) - length(replace(tags1,',',''))) and device_id_md5 = '${dmpreport.device_id_md5}'">
                     <field column="tag" name="tags1" />
                </entity>
                <entity name="crowds" query="select reverse(substring_index(reverse(substring_index(crowds,',',id)),',',1)) as crowd from t_device_info,t_int where id <= 1+(length(crowds) - length(replace(crowds,',',''))) and device_id_md5 = '${dmpreport.device_id_md5}'">
                     <field column="crowd" name="crowds" />
                </entity>
        </entity>
    </document></dataConfig>

第二步:在solrconfig.xml配置:

  <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
     <lst name="defaults">
       <str name="config">db-data-config.xml</str>
     </lst>
  </requestHandler>

第三步:将DIH需要的jar包拷贝到$SOLR_HOME/server/solr-webapp/webapp/WEB-INF/lib下

#>cp $SOLR_HOME/dist/solr-dataimporthandler-*.jar  $SOLR_HOME/server/solr-webapp/webapp/WEB-INF/lib

最后下载5.x最新版本的mysql驱动放到$SOLR_HOME/server/solr-webapp/webapp/WEB-INF/lib下载即可。


鐏嫄鎴浘_2017-01-14T14-30-01.251Z.png


关键字:   无
评论信息
暂无评论
发表评论
验证码: 
Powered by IMZHANGJIE.CN Copyright © 2015-2025 粤ICP备14056181号