Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add distinct values in a multivalue field in solr

I have a multivalue field called category(which is also a store field) in which i need to add only distinct values

<field name="category">value1</field>
<field name="category">value2</field>

If I do a update as follows
<add>
<doc>
<field name="id">E02</field>
<field name="category" update="add">value2</field>
</doc>
</add>

I get the value2 stored twice
<field name="category">value1</field>
<field name="category">value2</field>
<field name="category">value2</field>

I need to store/update only disctinct values in category fields which is a multivalue fields. How to do this solr?

Thanks in advance, Jagadesh.

like image 560
Jagadesh Avatar asked Apr 09 '13 12:04

Jagadesh


2 Answers

This functionality has been added for Solr 7.3.

You can use the add-distinct atomic update action, instead of add

See the Jira issue (SOLR-11267) and the documentation in the Reference Guide:

add-distinct

Adds the specified values to a multiValued field, only if not already present. May be specified as a single value, or as a list.

like image 151
DNA Avatar answered Nov 17 '22 12:11

DNA


One can "set" instead of "add", to recreate a stored field in partial document updates. So if it is the case where you have all the field values,just stick them in a Set and then repopulate the field. You have all the data to recreate it because of stored field requirement.

like image 2
Ion Cojocaru Avatar answered Nov 17 '22 12:11

Ion Cojocaru