Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to do solr Dataimport (i.e from RDBMS) using java API?

How to do solr Dataimport (i.e from RDBMS) using java API?

New Contributor

I am new to solr ,actually I tried Database table indexing in solr manually,i.e creating a new data-config.xml and running the full import from solr webUI, successfully did that.But now I need to do the same thing in java.So I need know the following things using java.

  1. How to set solr datasource in java api.
  2. How to set the entity and query
  3. How to run full import .

Actually ,for data import we write a configuration file like below

<?xml version="1.0" encoding="UTF-8" ?>

    <dataConfig>
    <dataSource type="JdbcDataSource" 
                driver="com.mysql.jdbc.Driver"                url="jdbc:mysql://localhost:3306/test_db" 
                user="root" 
                password="cloudera"/>
    <document>
      <entity name="emp"  
        query="select id,name from emp">
         <field column="id" name="id"/>
         <field column="name" name="name"/>       
      </entity>
    </document>
    </dataConfig>

and this configuration file information we will provide in solrconfig.xml like below

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

But my requirement is ,I don't want to configure any xml file like above,just I want do it all from java only ,so I need to set all the configurations which I have given in above xml from java code itself,i.e something like below

ModifiableSolrParams params = new ModifiableSolrParams();
params
.set("Datasource","JdbcDataSource") params.set("driver","com.mysql.jdbc.Driver")params.set("url","jdbc:mysql://localhost:3306/test_db")params.set("user","cloudera")params.set("password","cloudera")
params.set("query","select * from emp"),etc.

I think   my requirement is clear.If not please ask me .Please help to do this.Its urgent ,It would be really so much helpful for me...

Many many Thanks in advance..

Don't have an account?
Coming from Hortonworks? Activate your account here