Sathyakumar Seshachalam
Sathyakumar Seshachalam

Reputation: 2053

Atomic update not working Spring data solr

I have a Spring data solr project, and my repository class is a simple SolrCrudRepository. My question is how to make Spring data solr use atomic update feature of Solr 4. In other words, in order for atomic updates to work, what extra configuration do I need to make, so that Repository.save() works.

Upvotes: 1

Views: 1306

Answers (2)

Mirza Shujathullah
Mirza Shujathullah

Reputation: 1

        SolrInputDocument doc = new SolrInputDocument();
        Map<String, String> partialUpdate = new HashMap<>();
        partialUpdate.put("set", "value to update");
        doc.addField("id", "100");
        doc.addField("field name ", partialUpdate);
        UpdateRequest up = new UpdateRequest();
        up.setBasicAuthCredentials("username", "@password");
        up.add(doc);
        up.process(solrClient, "corename");
        up.commit(solrClient, "corename");

Upvotes: 0

Christoph Strobl
Christoph Strobl

Reputation: 6726

Use PartialUpdate along with SolrTemplate.

PartialUpdate update = new PartialUpdate("id", "123456789");
update.setValueOfField("name", "updated-name");
solrTemplate.saveBean(update);
solrTemplate.commit();

Please have a look at ITestSolrTemplate.

Upvotes: 1

Related Questions