简体   繁体   中英

Fully-Importing MySQL database to Solr 4 gives 404 error

Yet another Solr 4 new user. I admired what is Solr able to do in full text searching, but the on-line documentation is a little bit frustrating. Anyway, I'm working on importing my MySQL database (having few millions of records) to Solr.

  • I downloaded the Java connector and save it in the example/lib directory.
  • I created data-config.xml and put within it:

     <document name="doc"> <entity name="pagey" query="SELECT * FROM page"> <field column="id" name="pid" /> <field column="Content" name="pcontent" /> <field column="bid" name="bid" /> <field column="Num" name="num" /> </entity> </document> 

    and saved it in: /example/solr/collection1/conf .

  • Linked that file to solrconfig.xml by adding:

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

  • Modified schema.xml to add my new fields.

But when I arrived to perform full importing by interring: http://[localhost]:8983/solr/dataimport?command=full-import I got this error: HTTP ERROR 404 Problem accessing /solr/dataimport. Reason: Not Found HTTP ERROR 404 Problem accessing /solr/dataimport. Reason: Not Found . I think this is no more valid in the last version 4. So I tried: http://[localhost]:8983/solr/#/collection1/dataimport?command=full-import but nothing happens.

My fields have been successfully added, I can see them on the admin panel in the schema browser section in collection1.

From the admin -> collection1 -> Dataimport, it show: sorry, no dataimport-handler defined! . Running the start.jar doesn't show errors.

What am I missing right here?

EDIT: After solving it, remember that "XML is case-sensitive".

You data-config needs to look more like this. You are not specifying a mysql host, user, or password.

<dataConfig>
    <dataSource type="JdbcDataSource"
   driver="com.mysql.jdbc.Driver"
   url="jdbc:mysql://127.0.0.1:8889/yourdatabase"
   user="mysql_user"
   password="mysql_password"/>

<document name="doc">
    <entity name="pagey" query="SELECT * FROM page">

        <field column="id" name="pid" />
        <field column="Content" name="pcontent" />
        <field column="bid" name="bid" />
        <field column="Num" name="num" />
    </entity>
</document>
</dataConfig>

You need to include this in your solrconfig.xml file.

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

and

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

In solr.xml you need to make sure you have the following

<solr persistent="true" sharedLib="../lib">
If you are using latest Solr then use 

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


instead of

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

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