How do I add one document to solr index using solrj?

流过昼夜 提交于 2019-12-07 16:31:21

问题


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?


回答1:


Are you looking for something like this?

public void insertOneDoc() throws SolrServerException, IOException {
  HttpSolrServer solr = new HttpSolrServer(solrIndexPath);
  SolrInputDocument doc = new SolrInputDocument();
  doc.addField("fieldName", "fieldValue");
  solr.add(doc);
  solr.commit();
}

Because that adds a single document to your index that the HttpSolrServer refereces.




回答2:


Mmmm....I'm not sure if this is possible with DIH. I mean, depending on what you mean with "whole thing" (because a change in the index, even a single document, needs an index rebuild) you could index one document in this way

1) delta import If that single record is somethjng that has been changed and that change is something you can identify with a database column (e.g. a timestamp), then you csn use the delta import capability of DIH

2) change & reload - change the dih-config modifying the query to select that single record

  • reload the DIH configuration

  • re-issue the full import



来源:https://stackoverflow.com/questions/29521859/how-do-i-add-one-document-to-solr-index-using-solrj

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!