user7855273
user7855273

Reputation:

how to update multiple documents without id in solr database?

I have 1.000.000 records in my solr database. I want to update all records without unique key id, but I get error unique key is required! my solr document is :

  {
  id = 001, 
  name="Joe", 
  city = [Hyderabad], 
  phone = [9848022337]
  }

Here is my code.

  //Preparing the Solr client 

  //Preparing the Solr document 

  SolrInputDocument doc = new SolrInputDocument();  

  Map map=new HashMap();
  map.put("set","Ahmet");
  doc.addField("name", map);

  // or adding id list 
  // List ids = new ArrayList();
 // doc.addField("id",ids); 


  updateRequest.add( doc );  
  UpdateResponse rsp = updateRequest.process(Solr);

how can I do that, any alternative?

similar sql is update tableName set name="ahmet"

Upvotes: 0

Views: 1278

Answers (1)

MatsLindh
MatsLindh

Reputation: 52902

You can't.

Any update in Solr must reference the uniqueKey of the existing document - there is no functionality like update by query or similar to UPDATE foo SET bar = 'baz' WHERE field = 'spam';. The uniqueKey field is what defines if a new document is created or the old one is overwritten.

In your example it seems you have an id field that is unique, but if that's not the case, you can configure Solr to assign a unique id to each document when it's added to the index. You'll then have to reference that id when updating the existing document.

Upvotes: 3

Related Questions