如何使用solrj将一个文档添加到solr索引? [英] How do I add one document to solr index using solrj?
本文介绍了如何使用solrj将一个文档添加到solr索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用以下代码重新索引整个solr核心:
I can reindex an entire solr core using the following code:
public void indexSolr() throws SolrServerException, IOException {
HttpSolrServer solr = new HttpSolrServer(solrIndexPath);
logger.info("Indexing fcv solr at " + solrIndexPath);
// reindex to pickup new articles
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/" + solrDataImportPath);
params.set("command", "full-import");
params.set("clean", "true");
params.set("commit", "true");
solr.query(params);
}
如何只将一个文档插入索引而无需索引整件事?
How can I insert just one single document into the index without having to index the whole thing?
推荐答案
你在找这样的东西吗?
public void insertOneDoc() throws SolrServerException, IOException {
HttpSolrServer solr = new HttpSolrServer(solrIndexPath);
SolrInputDocument doc = new SolrInputDocument();
doc.addField("fieldName", "fieldValue");
solr.add(doc);
solr.commit();
}
因为这会为您的索引添加一个HttpSolrServer引用的文档。
Because that adds a single document to your index that the HttpSolrServer refereces.
这篇关于如何使用solrj将一个文档添加到solr索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文