I want to run dataimport in Solr using Java. I have gone through link Solrj full-import not working , there they have just given how to run the full import command from Java, and in some other links I found how to query the Solr indexed data, but actually my requirement is, 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,ie something like below
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"),etc.
Here, if you set another parameter, you can pass your entire XML as a string and execute the configuration:
params.set("dataConfig", <the data-import xml as string>);
I am late to the party, but in case anyone is looking for a solution to a similar problem, this can probably help.
Also, I would also like to mention this post, How to do Solr Data import (ie from RDBMS) using Java API? .
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.