我正在測試索引文檔的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());
}
}
}
我猜'solr.commit()'可能會解決這個問題。 –