@Test public void test1() throws SolrServerException, IOException{ //创建一个连接 HttpSolrServer server = new HttpSolrServer("http://localhost:8088/solr/core1"); //创建一个文档对象 SolrInputDocument document = new SolrInputDocument(); document.addField("id", "1"); document.addField("title", "哈哈"); //把文档对象写入索引库 server.add(document); //提交 server.commit(); }
特别注意:
url要加上对应的库,如果
HttpSolrServer server = new HttpSolrServer("http://localhost:8088/solr");这样不指定在哪个core下会报错,
一定要这样
HttpSolrServer server = new HttpSolrServer("http://localhost:8088/solr/core1");