将msql db导入solr时出错

时间:2014-06-27 15:32:03

标签: solr

我试图导入一个mysql数据库,其中包含许多其他表中的位置,用户,帖子,注释。我希望使用solr为我的网络应用程序构建搜索引擎,以搜索帖子和评论。所以我添加了以下内容: 1)到db-data-config.xml

<dataConfig>

    <dataSource
        type="JdbcDataSource"
        driver="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost/apnistreet"
        user="root"
        password="password"
    />
    <document>
        <entity name="location" query="select id from location">
            <entity name="user" query="select id from user where location_id=${location.id}">
                <entity name="post" query="select id,post,user_id from post where user_id=${user.id} order by time desc"> 
                    <field column="post" name="POST"/>
                    <entity name="comment" query="select comment,id,post_id,user_id 
                                      from comment where post_id={post.id} 
                                      order by time desc">
                        <field column="comment" name="COMMENT"/>
                    </entity>
                </entity>
            </entity>
        </entity> 
    </document> 
</dataConfig>

这些表包含许多其他列,但我只需要返回这些字段,所以我认为我不需要添加它们。

2)我在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>

  <lib dir="../../../lib/" regex="mysql-connector-java-5.1.29-bin.jar" />
  <lib dir="../../../dist/" regex="solr-dataimporthandler-\d.*\.jar" />
  <lib dir="../../../contrib/dataimporthandler/lib" regex=".*\.jar" />

3)对于schema.xml,我添加了:

<field name="id" type="int" indexed="true" stored="true" required="true" multiValued="false" /> 
   <field name="location_id" type="int" indexed="true" stored="true" required="true" multiValued="false" /> 
   <field name="user_id" type="int" indexed="true" stored="true" required="true" multiValued="false" /> 
   <field name="post_id" type="int" indexed="true" stored="true" required="true" multiValued="false" /> 
   <field name="POST" type="text_general" indexed="true" stored="true" multiValued="true"/>
   <field name="COMMENT" type="text_general" indexed="true" stored="true" multiValued="true"/>
   <field name="time" type="long" indexed="false" stored="true" multiValued="true"/>

然后我跑了  java -jar start.jar

为了加载数据,我去了网址 本地主机:8983 / solr的/ dataimport命令=全进口

但它给出了以下错误,我不知道如何去做:

    HTTP ERROR 500

    Problem accessing /solr/. Reason:



 {msg=SolrCore 'collection1' is not available due to init failure: Error opening new searcher,trace=org.apache.solr.common.SolrException: SolrCore 'collection1' is not available due to init failure: Error opening new searcher
    at org.apache.solr.core.CoreContainer.getCore(CoreContainer.java:827)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:305)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:205)
    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)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
    at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:942)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1004)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
    at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)
    at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.solr.common.SolrException: Error opening new searcher
    at org.apache.solr.core.SolrCore.<init>(SolrCore.java:844)
    at org.apache.solr.core.SolrCore.<init>(SolrCore.java:630)
    at org.apache.solr.core.CoreContainer.createFromLocal(CoreContainer.java:562)
    at org.apache.solr.core.CoreContainer.create(CoreContainer.java:597)
    at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:258)
    at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:250)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    ... 1 more
Caused by: org.apache.solr.common.SolrException: Error opening new searcher
    at org.apache.solr.core.SolrCore.openNewSearcher(SolrCore.java:1521)
    at org.apache.solr.core.SolrCore.getSearcher(SolrCore.java:1633)
    at org.apache.solr.core.SolrCore.<init>(SolrCore.java:827)
    ... 11 more
Caused by: java.lang.NumberFormatException: For input string: "1.gen"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Long.parseLong(Long.java:441)
    at org.apache.lucene.index.SegmentInfos.generationFromSegmentsFileName(SegmentInfos.java:248)
    at org.apache.lucene.index.SegmentInfos.getLastCommitGeneration(SegmentInfos.java:183)
    at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:746)
    at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:694)
    at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:400)
    at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:746)
    at org.apache.solr.update.SolrIndexWriter.<init>(SolrIndexWriter.java:77)
    at org.apache.solr.update.SolrIndexWriter.create(SolrIndexWriter.java:64)
    at org.apache.solr.update.DefaultSolrCoreState.createMainIndexWriter(DefaultSolrCoreState.java:267)
    at org.apache.solr.update.DefaultSolrCoreState.getIndexWriter(DefaultSolrCoreState.java:110)
    at org.apache.solr.core.SolrCore.openNewSearcher(SolrCore.java:1484)
    ... 13 more
,code=500}

    Powered by Jetty://

错误是否来自声明实体和字段或其他原因的错误技术。 Plz帮我解决了这个问题。

2 个答案:

答案 0 :(得分:0)

我把我的问题整理得非常狡猾:

 <lib dir="../../../lib/" regex="mysql-connector-java-5.1.29-bin.jar" />
  <lib dir="../../../dist/" regex="solr-dataimporthandler-\d.*\.jar" />
  <lib dir="../../../contrib/dataimporthandler/lib" regex=".*\.jar" />

应该是最后一行,因为它是mysql-connector jar,应该在调用DIH后严格调用。

 <lib dir="../../../dist/" regex="solr-dataimporthandler-\d.*\.jar" />
 <lib dir="../../../contrib/dataimporthandler/lib" regex=".*\.jar" />
 <lib dir="../../../lib/" regex="mysql-connector-java-5.1.29-bin.jar" />

答案 1 :(得分:0)

确实,您必须包括路径中使用的数据库的.jar:

solr/contrib/dataimporthandler

然后您必须在solrconfig.xml的库部分中引用它

<lib dir="${solr.install.dir:../../../..}/contrib/dataimporthandler/lib" regex=".*\.jar" />

您还必须参考负责索引过程的solr-dataimporthandler.jar,这在路径中

solr/dist

库部分中再次包含以下行:

<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-.*\.jar" />