Reputation: 151
I want to update a particular field of a document in solr. However while trying to do so other fields of the document are becoming null.
CommonsHttpSolrServer server = new CommonsHttpSolrServer("http://mydomain:8983/solr/index_socialmedia/");
List<SolrInputDocument> solrInputDocsList = new ArrayList<SolrInputDocument>();
SolrInputDocument solrInputDoc = new SolrInputDocument();
solrInputDoc.addField("id","427832898745234516478592");
solrInputDoc.addField("city","Kolkata");
solrInputDocsList.add(solrInputDoc);
server.add(solrInputDocsList);
server.commit();
In the above code the "id" field is the unique field. How can I fix this problem.
Upvotes: 1
Views: 699
Reputation: 1444
I tried with the following code snippet. It's able to do partial update. Try this.
SolrServer server = new HttpSolrServer("http://mydomain:8983/solr/index_socialmedia/");
SolrInputDocument solrInputDoc = new SolrInputDocument();
Map<String, String> update = new HashMap<String, String>();
update.put("set", "Kolkata");
solrInputDoc.addField("id","427832898745234516478592");
solrInputDoc.addField("city", update);
server.commit();
Upvotes: 1
Reputation: 766
Which solr version are you using ? if it is bellow 4.0 ,solr does not support single field update (partial update) so in your case existing old document is deleted and new document is inserted with same id (Reason Solr does not support single field or partial update is lucene does not support partial update )
If you using Solr 4.0 you can refer this solrj api for partial document update
Upvotes: 0