public static void main(String[] args) throws Exception {
String zkHost = "192.168.137.200:2181,192.168.137.201:2181";
CloudSolrClient server = new CloudSolrClient(zkHost);
server.setDefaultCollection("mycollection");
addDocs(server);
query(server);
server.close();
}
public static void addDocs(CloudSolrClient server) throws Exception{
SolrInputDocument doc1 = new SolrInputDocument();
doc1.addField("id", "00003");
doc1.addField("content", "id测试");
SolrInputDocument doc2 = new SolrInputDocument();
doc2.addField("id", "00004");
doc2.addField("content", "id测试2");
Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
docs.add(doc1);
docs.add(doc2);
server.add(docs);
server.commit();
}
public static void query(CloudSolrClient server) throws Exception{
SolrQuery parameters = new SolrQuery();
parameters.set("q", "*:*");
parameters.set("qt", "/select");
parameters.set("collection", "mycollection");
QueryResponse response = server.query(parameters);
//SolrDocumentList list = response.getResults();
System.out.println(response);
}