How to import data from mysql to solr

2019-02-15 17:11发布

问题:

I am trying to do the full db import using below URL

    `127.0.0.1:8983/solr/dataimport?command=full-import`

I installed solr and trying to configure it. I changed few files and putted details (file names and added code is described below). But when I am trying to import the table data into solr json format it is showing below error:

    HTTP ERROR 404

    Problem accessing /solr/dataimport. Reason:

    Not Found
        Powered by Jetty://

Can anyone let me know what the actual problem is? Or did I misconfigure Sorl?


My data-config.xml file have below code:

<dataConfig>
  <dataSource type="JdbcDataSource" 
              driver="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost/sq_dbLoveOffers" 
              user="pksqueak" 
              password="passwd"/>
  <document>
    <entity name="id" 
            query="select sq_prom_id, sq_prom_name, sq_prom_description, sq_latitude, sq_longitude from sq_offers">
    </entity>
  </document>
</dataConfig>

I added below code into Solrconfig.xml:

<lib dir="../../../../contrib/dataimporthandler/lib/" regex=".*\.jar" />
<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>

I added below code in schema.xmal FILE:

<fields>
    <field name="sq_prom_id" type="string" indexed="true" stored="true" required="true" />
    <field name="sq_prom_name" type="string" indexed="true" stored="true" />
    <field name="sq_prom_description" type="string" indexed="true" stored="true" />
    <field name="sq_latitude" type="string" indexed="true" stored="true" />
    <field name="sq_longitude" type="string" indexed="true" stored="true" />
</fields>

回答1:

In case the core you address is not your default core, your request is lacking the core's name in the URL. You should request should be like this

127.0.0.1:8983/solr/<core-name>/dataimport?command=full-import

There you need to replace the <core-name> with the actual name of your core, as configured in your solr.xml.



回答2:

I used below command to run sorl server for DIH.

java -Dsolr.solr.home="./example-DIH/solr/" -jar start.jar

and I did the full import using below URL, it solved my problem.

http://127.0.0.1:8983/solr/db/dataimport?command=full-import


回答3:

I have a functioning Data Import Handler and you can compare configs with me if necessary http://amac4.blogspot.co.uk/2013/08/configuring-solr-4-data-import-handler.html