user3161879
user3161879

Reputation: 103

Solrdocument.addfield replace the document instead of updating the fields

iam trying to update 3 fields to solrj using solrinputdocument.addField("fieldname", "fieldvalue"); it generally replaces the complete document instead of updating these fields alone. Iam using solr 4.5 and iam not sure what is the issue. i also tried with setfield for solrinputdocument.setField and it didnt work. Please help. The sample code is :

String urlString = "http://serverip/solr/taag_webproducts/";
SolrServer solr = new HttpSolrServer(urlString);

UpdateRequest up = new UpdateRequest("/update");
solrinputdocument.addField(fieldname, fieldvalue);
 up.add(solrinputdocument);
 solr.request(up);

Upvotes: 2

Views: 1788

Answers (1)

leoh
leoh

Reputation: 10618

Assuming you have the _version_ field defined in schema.xml:

<field name="_version_" type="long" indexed="true"  stored="true"/>

and also have an id field when assembling the SolrInputDocument (like the following example)

To do the atomic update/partial update, the map is the key

Map oper = new HashMap();
oper.put("set", 100);

SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "unique");
doc.addField("price", oper);

SolrServer server = getSolrServer();
server.add(doc);
server.commit();

Example taken from solrj-4-0-0-alpha-atomic-updates

Upvotes: 1

Related Questions