solr 4 data import handle configuration {mysql}

Set-Up

 

  • Firstly we need the libraries that are required to use Data Import Handler.
    setings env library in here
     
    install mysql-connector-java
    yum install mysql-connector-java.noarch
     
      Add this to the solrconfig.xml file:
     
    <lib dir="../../../contrib/dataimporthandler/lib/" regex=".*\.jar" />
    <lib dir="../../../dist/" regex="apache-solr-dataimporthandler-\d.*\.jar" />
     make sure 

    ls ../../../contrib/dataimporthandler/lib/
    activation-1.1.1.jar  mail-1.4.3.jar

    • Now we modify the solrconfig.xml file. Add the following :
       
         <!-- REQUEST HANDLER FOR DATAIMPORTHANDLER -->
        <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
                 <lst name="defaults">
                                 <str name="config">mysql-config.xml</str>
                                          </lst>
                                            </requestHandler>
       
      create file mysql-config.xml This is for the Data Import Handler configuration. It should look similar to:
       

      <dataConfig>
      <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
      url="jdbc:mysql://HOST/mydb" user="users"
      password="secret" />
      <document>
      <entity name="user" query="SELECT id, name from users">
      <field column="id" name="id" />
      <field column="name" name="name" />
      <entity name="birthday" query="select birthday from table where id=${user.id}">
      <field column="description" name="description" />
      </entity>
      </entity>
      </document>
      </dataConfig></dataConfig>
      • For other database engines enter the specific driver, url, user and password attributes.
        We now need to modify the fields section of the schema.xml file to something like the following snippet:
         
      • <field name="id" type="string" indexed="true" stored="true"
        required="true"/>
        <field name="name" type="text" indexed="true" stored="true" />
        <field name="birthday" type="text" indexed="true" stored="true"/>
        <field name="description" type="" indexed="true"
        stored="true"/>
         http://localhost:8080/solr/dataimport?command=full-import
         source  
         
       

Comments

  1. That is an extremely smart written article. I will be sure to bookmark it and return to learn extra of your useful information. Thank you for the post. I will certainly return.

    ReplyDelete
  2. Hi, Really great effort. Everyone must read this article. Thanks for sharing.

    ReplyDelete
  3. Amazing blog and very interesting stuff you got here!

    ReplyDelete

Post a Comment

Popular Posts