首页 > 编程语言 >Java读取csv导入solr

Java读取csv导入solr

时间:2022-12-10 11:03:35浏览次数:50  
标签:csvReader dwfdocs Java overviewdoc addField get csv solr

public static void main(String[] args)  {

try { //CsvReader csvReader = null;

CsvReader csvReader = new CsvReader(
"F:\\ImportData\\01.csv", ',');
csvReader.readHeaders();

SolrCloudServiceImpl solr = new SolrCloudServiceImpl();
Collection<SolrInputDocument> dwfdocs = new ArrayList<SolrInputDocument>();
// 读取每行的内容

while (csvReader.readRecord()) {
SolrInputDocument overviewdoc = new SolrInputDocument();
overviewdoc.addField("id", UUID.randomUUID().toString());
overviewdoc.addField("linkedinid_s",csvReader.get(0));
overviewdoc.addField("username_s",csvReader.get(1));
overviewdoc.addField("fb_s",csvReader.get(2));
overviewdoc.addField("tw_s",csvReader.get(3));
overviewdoc.addField("github_s",csvReader.get(4));
overviewdoc.addField("email_s",csvReader.get(5));
overviewdoc.addField("phone_s",csvReader.get(6));
dwfdocs.add(overviewdoc);
if(dwfdocs.size()>=10000){
solr.connectSolrCloud();
solr.indexData("solr库名字", dwfdocs);
dwfdocs.clear();
}
}
solr.connectSolrCloud();
solr.indexData("solr库名字", dwfdocs);

} catch (IOException e) {
e.printStackTrace();
}
}

标签:csvReader,dwfdocs,Java,overviewdoc,addField,get,csv,solr
From: https://blog.51cto.com/u_15907719/5927306

相关文章