分类: Java
2015-06-26 16:08:58
网上很多人在找Solrj更新一个或几个字段值的方法,下面把方法写出来,希望大家少浪费时间在这上面:
public static void update(String id, Object fieldValue) throws IOException, SolrServerException { HashMap<String, Object> oper = new HashMap<String, Object>(); oper.put("set", fieldValue); SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", id); doc.addField("fieldName", oper); HttpSolrClient client = new HttpSolrClient(baseURL); client.add(doc); client.commit(); }