Solr, how to use new field update modes (atomic updates) using SolrJ

Solr 4.x has this new new feature that lets you specify how fields with multiple values ​​will be updated when updating an existing document. In particular, you can say whether the updating document will replace the old values ​​of the multi-valued field with new ones or add new values ​​to existing ones.

I tried this with a request handler, as described here:

http://wiki.apache.org/solr/UpdateXmlMessages#Optional_attributes_for_.22field.22

I used curl to send xml, where some fields used a parameter update=add:

<field name="skills" update="add">Python</field>

This works as expected.

However, I cannot figure out how to do this with the Java API (SolrJ).

If I do something like this:

SolrInputDocument doc1 = new SolrInputDocument();
doc1.setField("ID_VENTE", "idv1");
doc1.setField("FACTURES_PRODUIT", "fp_initial");
solrServer.add(doc1);
solrServer.commit();

SolrInputDocument doc2 = new SolrInputDocument();
doc2.setField("ID_VENTE", "idv1");
doc2.setField("FACTURES_PRODUIT", "fp_2");    
solrServer.add(doc2);
solrServer.commit();

"FACTURES_PRODUIT" "fp_2" ( ). :

doc2.addField("FACTURES_PRODUIT", "fp_2");  

. SolrInputField, .

, : API- Solr 4 multiValued, ( ) ?

+3
1

, SolrJ. :

    SolrInputDocument doc2 = new SolrInputDocument();
    Map<String,String> fpValue2 = new HashMap<String, String>();
    fpValue2.put("add","fp2");        
    doc2.setField("FACTURES_PRODUIT", fpValue2);
+6

All Articles