简体   繁体   中英

Data Import in Solr 4.2 not working?

My data-config.xml is as follows and I have kept in the the Conf folder along with the solrconfig.xml :-

<dataConfig>
    <dataSource name="Sample" driver="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/Sample" user="postgres" password="P@ssword">
        <document name="oneDocs">
            <entity dataSource="Sample" name="entity1" query="select FirstName from Employee">
                <field column="EmpId" name="EmpId" />
                <field column="FirstName" name="FirstName" />
                <field column="LastName" name="LastName" />
            </entity>
        </document>
    </dataSource>
</dataConfig>

And my solrconfig.xml is as follows :-

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

I have also tried to add the libraries in the following ways :-

<lib dir="../../../contrib/extraction/lib" regex=".*\.jar" />
  <lib dir="../../../dist/" regex="solr-cell-\d.*\.jar" />

  <lib dir="../../../contrib/clustering/lib/" regex=".*\.jar" />
  <lib dir="../../../dist/" regex="solr-clustering-\d.*\.jar" />

  <lib dir="../../../contrib/dataimporthandler/lib/" regex=".*\.jar" />
  <lib dir="../../dist/" regex="solr-dataimporthandler-\d.*\.jar" />


  <lib dir="../../dist/" regex="postgresql-9.2-1002.jdbc3-\d.*\.jar" />

  <lib dir="../../../contrib/langid/lib/" regex=".*\.jar" />
  <lib dir="../../../dist/" regex="solr-langid-\d.*\.jar" />

  <lib dir="../../../contrib/velocity/lib" regex=".*\.jar" />
  <lib dir="../../../dist/" regex="solr-velocity-\d.*\.jar" />

  <!-- If a 'dir' option (with or without a regex) is used and nothing
       is found that matches, it will be ignored
    -->
  <lib dir="/total/crap/dir/ignored" /> 

I am getting the same error constantly :-

org.apache.solr.handler.dataimport.DataImportHandlerException: Data Config problem: DataImportHandler configuration file must have one <document> node.
    at org.apache.solr.handler.dataimport.DataImporter.loadDataConfig(DataImporter.java:226)
    at org.apache.solr.handler.dataimport.DataImporter.maybeReloadConfiguration(DataImporter.java:124)
    at org.apache.solr.handler.dataimport.DataImportHandler.handleRequestBody(DataImportHandler.java:168)
    at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)
    at org.apache.solr.core.SolrCore.execute(SolrCore.java:1797)
    at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:637)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:343)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:141)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
    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:365)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
    at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635)
    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(Unknown Source)
Caused by: org.apache.solr.handler.dataimport.DataImportHandlerException: DataImportHandler configuration file must have one <document> node.
    at org.apache.solr.handler.dataimport.DataImporter.readFromXml(DataImporter.java:250)
    at org.apache.solr.handler.dataimport.DataImporter.loadDataConfig(DataImporter.java:223)
    ... 32 more

Please help to resolve this.This is eating away most of the time. Thanks

NOTE: I am using Postgres and Apache Tomcat 7 and Java 7 .

Your data-config.xml is flawed. You have wrapped the document elment into the datasource element. Both need to be on the same level as direct child of the dataConfig element.

This is why the exception you posted states:

Data Config problem: DataImportHandler configuration file must have one node.

The XML parser does not find the document element as child node of dataConfig.

Try it like this:

<dataConfig>
    <dataSource name="Sample" driver="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/Sample" user="postgres" password="P@ssword" />
    <document name="oneDocs">
       <entity dataSource="Sample" name="entity1" query="select FirstName from Employee">
            <field column="EmpId" name="EmpId" />
            <field column="FirstName" name="FirstName" />
            <field column="LastName" name="LastName" />
        </entity>
    </document>
</dataConfig>

In your data-config.xml the document element should be a sibling to the dataSource element, not a child.

ie it should look like this;

<dataConfig>
  <dataSource>
    ..
  </dataSource>
  <document>
    ..
  </document>
</dataConfig>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM