What's the difference between Document.addField and Document.setField in solrj?

时间:2017-06-12 16:56:00

标签: java search solr solrj

While adding documents to an index in solr, I've noticed there are two ways to add data one is to addField another is to setField. Can you tell me when to use which method?

SolrInputDocument doc = new SolrInputDocument();
doc.setField("field_name", data);
doc.addField("field_name_2", data2);

1 个答案:

答案 0 :(得分:1)

SolrInputDocument.addField() - it will add another value to any existing values for the field.It works like an append

SolrInputDocument.setField() - it will overwrite anything that is already there.Discard existing values and start with a fresh list of values.