String zk= "127.0.0.1:2183"; String root="/solr"; CloudSolrClient solrClient=new CloudSolrClient(zk+root); solrClient.connect(); SolrInputDocument doc = new SolrInputDocument(); Map<String, String> partialUpdate = new HashMap<String, String>(); partialUpdate.put("set", "純植物染髮1次男女不限僅限短髮,提供免費WiFi"); doc.addField("grouponId", "123456"); doc.addField("name", partialUpdate); Map<String,List<String>> cities=new HashMap<String, List<String>>(); List list=new ArrayList(); list.add("北京"); list.add("長春"); cities.put("set",list); doc.addField("city",cities); doc.addField("_version_",1); Map<String,String> subCat=new HashMap<String, String>(); subCat.put("add","美容"); doc.addField("subCat",subCat); Map<String,Long> price=new HashMap<String, Long>(); price.put("inc",100L); doc.addField("price",price); try { solrClient.add("groupon",doc); solrClient.commit("groupon"); } catch (SolrServerException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { solrClient.close(); } catch (IOException e) { e.printStackTrace(); }
{ grouponId: "123456", cat: [ "麗人" ], subCat: [ "美髮" ], name: "純植物染髮1次男女不限僅限短髮,提供免費WiFi1", price: 67.80000305175781, startTime: "2015-08-31T06:16:35Z", endTime: "2016-06-25T15:59:59Z", postTime: "2015-11-04T10:25:33.914Z", city: [ "北京市", "長春市" ], region: [ "新鄭市" ], district: [ "炎黃廣場" ], _version_: 1535465635791765500 }
{ grouponId: "123456", cat: [ "麗人" ], subCat: [ "美髮", "美容" ], name: "純植物染髮1次男女不限僅限短髮,提供免費WiFi", price: 167.8000030517578, startTime: "2015-08-31T06:16:35Z", endTime: "2016-06-25T15:59:59Z", postTime: "2015-11-04T10:25:33.914Z", city: [ "北京", "長春" ], region: [ "新鄭市" ], district: [ "炎黃廣場" ], _version_: 1535467687828783000 }