First, you cannot do any internal editing of a multi-valued list, other than:

1. Replace the entire list.
2. Add values on to the end of the list.

But you can do both of those operations on a single multivalued field with "atomic update" without reading and writing the entire document.

Second, there is no "<arr>" element in the Solr Update XML format. Only "<field>".

To simply replace the full, current value of one multi-valued field:

<add>
 <doc>
   <field name="id">doc-id</field>
   <field name="tags" update="set">a</field>
   <field name="tags" update="set">b</field>
 </doc>
</add>

If you simply want to append a couple of values:

<add>
 <doc>
   <field name="id">doc-id</field>
   <field name="tags" update="add">a</field>
   <field name="tags" update="add">b</field>
 </doc>
</add>

To empty out a multivalued field:

<add>
 <doc>
   <field name="id">doc-id</field>
   <field name="tags" update="set" null="true" />
 </doc>
</add>

-- Jack Krupansky

-----Original Message----- From: Dotan Cohen
Sent: Thursday, May 30, 2013 7:55 AM
To: solr-user@lucene.apache.org
Subject: Removing a single value from a multiValue field

I have a Solr application with a multiValue field 'tags'. All fields
are indexed in this application. There exists a uniqueKey field 'id'
and a '_version_' field. This is running on Solr 4.x.

In order to add a tag, the application retrieves the full document,
creates a PHP array from the document structure, removes the
'_version_' field, and then adds the appropriate tag to the 'tags'
array. This is all then sent to Solr's update method via HTTP with
'overwrite=true'. Solr correctly replaces the extant document with the
new document, which is identical with the exception of a new value for
the '_version_' field and an additional value in the multiValued field
'tags'. This all works correctly.

I am now adding a feature where one can remove tags. I am using the
same business logic, however instead of adding a value to the 'tags'
array I am removing one. I can confirm that the data being sent to
Solr does not contain the removed tag. However, it seems that the old
value for the multiValue field is persisted, that is the old tag
stays. I can see that the '_version_' field has a new value, so I see
that the change was properly commited.

Is there a known bug that overwriting such a doc...:
<doc>
   <arr name="tags">
       <str>a</str>
       <str>b</str>
</arr>
</doc>

...with this doc...:
<doc>
   <arr name="tags">
       <str>a</str>
</arr>
</doc>

...has no effect? Can multiValue fields be only added, but not removed?

Thanks.

--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com

Reply via email to