利用 solrj 提交索引

首先创建一个 SolrInputDocument 对象,然后设置其字段值,通过 SolrServer’s  的 add() 方法,将文档提交给 solr,实例代码如下:

String urlString = "http://localhost:8983/solr";
SolrServer solr = new CommonsHttpSolrServer(urlString);
SolrInputDocument document = new SolrInputDocument();
document.addField("id", "552199");
document.addField("name", "Gouda cheese wheel");
document.addField("price", "49.99");
UpdateResponse response = solr.add(document);
//最后记得 commit 使索引生效</div>
solr.commit();

Copyright © All Rights Reserved · Green Hope Theme by Sivan & schiy · Proudly powered by WordPress