You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by edo <ed...@gmail.com> on 2013/09/13 12:50:49 UTC

Empty out a multiValue Field using SolrJ

Hi all,
i am facing an issue while trying to update a document.
I am using SolrJ to add/update documents of my collection. The SolrJ
version is 4.0.0 ( but i also tried with the latest 4.4.0 )

I am aware that in multivalue fields i can only add an element but not
remove, in fact for those fields I am overriding all the values every time.
Everything worked great until I found a corner case: empty out a multivalue
field.
In this case values stay there and the field is not emptied.

I tried to look on the previous ML threads and i found something useful
here:
http://www.searchworkings.org/forum/-/message_boards/view_message/585466

Using CURL i posted a JSON update and the field has been emptied. However
when i tried to apply the same solution using SolrJ i didn't get the
expected result.

This is the code snippet:

 Map<String, Object> element = new HashMap<String, Object>(1);
 element.put("set", null);
 this.addField("fieldname", element);

Am I doing something wrong? Did anyone else face the same issue?

Thanks in advance,
Edo

Re: Empty out a multiValue Field using SolrJ

Posted by Chris Hostetter <ho...@fucit.org>.
: i am facing an issue while trying to update a document.
: I am using SolrJ to add/update documents of my collection. The SolrJ

: I am aware that in multivalue fields i can only add an element but not
: remove, in fact for those fields I am overriding all the values every time.
: Everything worked great until I found a corner case: empty out a multivalue
: field.
: In this case values stay there and the field is not emptied.

	...

: This is the code snippet:
: 
:  Map<String, Object> element = new HashMap<String, Object>(1);
:  element.put("set", null);
:  this.addField("fieldname", element);

just to be clear:

1) is "this" in your above code a SolrInputDocument object?  are you 
subclassing SolrInputDocument for some reason? can you explain why?

2) IIUC, you are using solrj to fecth a document from solr, and you then 
want to use Atomic updates to modify that document, and one of hte 
modifications you are attempting is to empty out this multivalued field -- 
correct?   But if the field currently has values, then "addField" is going 
to add your 1 element map to that existing list of values.  Have you tried 
using SolrInputDocument.setField("fieldname", element); to *replace* all 
of the existing values with the instruction to set the (on the server 
side) to null?

If i'm missunderstanding any part of your question, please post a more 
complete (ideally: runnably) code example showing everything you are 
doing.


-Hoss