update: as I describe in the mailing list (see reply here), I found that in the solrj api, the value of a SolrInputField can be a map - it doesn't have to be a simple scalar value. If it is a map, solrj adds an additional
update
attribute to the field's xml element. For example, This code:SolrInputDocument doc = new SolrInputDocument();
Map<String, String> partialUpdate = new HashMap<String, String>();
partialUpdate.put("set", "foo");
doc.addField("id", "test_123");
doc.addField("description", partialUpdate);
yields this document:
<doc boost="1.0">
<field name="id">test_123</field>
<field name="description" update="set">foo</field>
</doc>
In this example I used the word "set" for this additional attribute, but it doesn't work. Solr doesn't update the field as I expected. According to this link: http://solr.pl/en/2012/07/09/solr-4-0-partial-documents-update/ valid values are "set" and "add".
he key of the hash map can be one of three values:
- set - to set a field.
- add - to add to a multi-valued field.
- inc - to increment a field.
There is an example of this code in the solrj unit tests, in a method called
Test Code: http://svn.apache.org/repos/asf/lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
testUpdateField
.Test Code: http://svn.apache.org/repos/asf/lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
Read full article from solr - solrj api for partial document update - Stack Overflow
No comments:
Post a Comment