码迷,mamicode.com
首页 > 其他好文 > 详细

将Mysq数据导入solr索引库

时间:2015-08-13 14:07:17      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:

本文的基础环境都是在centos 64bit,jdk1.7.79

将mysql 的jar 包添加到/home/hadoop/cloudsolr/solr-4.10.4/contrib/dataimporthandler/lib 下

修改对应的solrconfig.xml 文件我的core 是collection1,配置文件example/solr/collection1/conf/solrconfig.xml

在配置文件中添加了:
  <lib dir="/home/hadoop/cloudsolr/solr-4.10.4/dist/" regex="solr-dataimporthandler-\d.*\.jar" />
   <lib dir="/home/hadoop/cloudsolr/solr-4.10.4/contrib/dataimporthandler/lib/" regex=".*\.jar" />

还是在solrconfig配置文件中

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

 

vim db-data-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>  
    <dataSource driver="com.mysql.jdbc.Driver"    
                    url="jdbc:mysql://ip:3306/database"     
                                    user="laiba"     
                                     password="laiba123"   
                                                                   <span style="color:#FF0000;"> batchSize="-1"</span>/><!-- 注意:mysql中一定要batchSize="-1" 否则会报异常-->
    <document>  
            <entity name="bns_article" pk="id"  
                            query="select id,title,author,cover,digest, content from bns_article"  
                                            deltaImportQuery="select id,title, author, cover,digest, content from bns_article where id=‘${dataimporter.delta.ID}‘"  
                                                            deltaQuery="select id,title, author, cover, digest,content from bns_article where  to_char(updatetime,‘yyyy-mm-dd hh24:mi:ss‘)> ‘${dataimporter.last_index_time}‘">
                                                                        <field column="id" name="id"/>  
                                                                                    <field column="title" name="title"/>                  
                                                                                     <field column="author" name="author"/>                           
                                                                                     <field column="cover" name="cover"/>  
                                                                                     <field column="digest" name="digest"/>
                                                                                     <field column="content" name="content"/>
                                                                                      </entity>                    
                                      </document>                                                                        
                                       </dataConfig>    

 第三:配置schema.xml文件 添加一下字段(也就是要生成索引的数据库字段) (根据上一篇IK分词的设置,也可以把字段设置成需要分词的)

添加2个字段:

   <field name="cover" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="digest" type="string" indexed="true" stored="true" multiValued="false"/>

 重启服务后出现错误提示:

HTTP ERROR 500

Problem accessing /solr/. Reason:

    {msg=SolrCore ‘collection1‘ is not available due to init failure: RequestHandler init failure,trace=org.apache.solr.common.SolrException: SolrCore ‘collection1‘ is not available due to init failure: RequestHandler init failure
    at org.apache.solr.core.CoreContainer.getCore(CoreContainer.java:745)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:347)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:207)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
    at org.eclipse.jetty.server.Server.handle(Server.java:368)

问题原因:

   <!-- the dataimport requestHandler --> 
       <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport. DataImportHandler"> 
               <lst name="defaults"> 
              <str name="config">db-data-config.xml</str> 
             </lst> 
       </requestHandler> 
将<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport. DataImportHandler"> 换行了。

解决办法:
将<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport. DataImportHandler"> 调整在一行即可

 

打开集群

导入数据

技术分享

查询

技术分享

 

参考地址:http://wiki.apache.org/solr/DIHQuickStart

将Mysq数据导入solr索引库

标签:

原文地址:http://www.cnblogs.com/zhanggl/p/4726901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!