2016-04-21 83 views
0

我正在測試索引文檔的SolrJ代碼。 當我執行我的代碼時,它看起來像正常工作。 但執行後,當我檢查Solr UI上的預期結果時,它不顯示任何內容。但重新啓動Solr後,它會在Solr UI上正確顯示預期的結果。使用SolrJ索引文檔

如何在不重新啓動Solr的情況下獲取索引文檔?

我的Solr的版本:5.2.1 請參考下

import java.io.IOException; 
import org.apache.solr.client.solrj.SolrClient; 
import org.apache.solr.client.solrj.SolrServerException; 
import org.apache.solr.client.solrj.impl.HttpSolrClient; 
import org.apache.solr.client.solrj.response.UpdateResponse; 
import org.apache.solr.common.SolrInputDocument; 
import org.apache.solr.common.*; 

public class addDocument { 

    public static void main(String[] args) throws IOException, 
      SolrServerException { 
     try { 

      String urlString = "http://(SolrServer)/solr/test_core/"; 
      SolrClient solr = new HttpSolrClient(urlString); 
      SolrInputDocument doc = new SolrInputDocument(); 
      // indexing a document 

      doc.addField("id", "12311122113"); 
      doc.addField("title", "Insertion Completed"); 

      UpdateResponse response = solr.add(doc); 
      System.out.println("Done"); 
     } catch (Exception e) { 
      System.out.println(e.getMessage()); 
     } 
    } 
} 
+2

我猜'solr.commit()'可能會解決這個問題。 –

回答

0

您需要的文件索引過程完成後提交我的Java代碼。所以如果你重新啓動solr,它會自動提交。如果你不想重新啓動Solr。您可以通過

  1. 嘗試重新載入核心(參見下面的網址,根據您改變URL名稱)

    http://127.0.0.1:8080/solr/admin/cores?action=RELOAD&core=core1

  2. 使用solr.commit();在你的代碼

+0

謝謝你的協助 –