1

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.

Vijay Tiwary
  • 151
  • 10

3 Answers3

1

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();
buddy86
  • 1,434
  • 12
  • 20
  • Thanks a ton. Its getting updated. However I have to update 6.8 million records in Slor 4.4 with two sharded cloud environment having 7 GB RAM for each shard. Around 1 million records are getting updated and after that one of the shards is crashing because of low memory. Any clue on this? – Vijay Tiwary Mar 20 '14 at 06:17
0

Set <uniqueKey>id</uniqueKey> in your solr schema.xml

user3331198
  • 184
  • 7
  • It's not the problem with **uniqueKey**. Vijay has mentioned that in his question."**the "id" field is the unique field**" – buddy86 Feb 25 '14 at 12:43
0

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

Community
  • 1
  • 1
GaneshP
  • 746
  • 7
  • 25