2016-02-24 44 views
0

我试图让多值字段应该只存储唯一值。 当我试图使用部分更新(原子更新使用“添加”)添加值。 如果该值已经存在于多值字段中,则不应该增加值。如何在多值字段中添加/存储唯一值?

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 

回答

0

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

{ "id": "36", 
    "name": { "set": [ "RAJEEV CHAUHAN","Alex","ERICK" ] } 
} 
相关问题