如何在多值字段中仅添加/存储不同的值?

时间:2016-02-24 05:05:08

标签: solr solrj

我正在尝试使用多值字段,该字段只应存储唯一值。     当我尝试使用部分更新添加值时(使用“add”进行原子更新)。     如果它已存在于该多值字段中,则不应添加值。

For example:
<field name="name" type="text_general" indexed="true" stored="true" multiValued="true"/>    

first adding values into field :
{"id":"36",
 "name":["RAJEEV CHAUHAN","Alex"]
}
Now values in the "name" field  are as follows"name":["RAJEEV CHAUHAN","Alex"].


second time when I add using partial update "add" as below,
{"id":"36",
 "name":{"add":["RAJEEV CHAUHAN","Alex","ERICK"]}
}
Now the values in the field should be "name":["RAJEEV CHAUHAN","Alex","ERICK"], it should not be 
 "name":["RAJEEV CHAUHAN","Alex","RAJEEV CHAUHAN","Alex","ERICK"]

How can I achieve these functionality?

Thanks in advance 

1 个答案:

答案 0 :(得分:0)

你想做的事是不可能的。您最好阅读客户端中的值,并使用“set”命令而不是“add”发布更新 - 例如。

{ "id": "36",
  "name": { "set": [ "RAJEEV CHAUHAN","Alex","ERICK" ] }
}