# "Set" operations on elasticsearch document field

**URL:** <https://discuss.elastic.co/t/set-operations-on-elasticsearch-document-field/88712>\
**Category:** Elasticsearch\
**Created:** [June 8, 2017, 12:16pm UTC](https://discuss.elastic.co/t/set-operations-on-elasticsearch-document-field/88712 "2017-06-08T12:16:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yesu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yesu/32/48857_2.png) [@yesu](https://discuss.elastic.co/u/yesu)\
**Post date:** [June 8, 2017, 12:16pm UTC](https://discuss.elastic.co/t/set-operations-on-elasticsearch-document-field/88712/1 "2017-06-08T12:16:27Z")

</div>

Hi,

Is there any way to achieve "set" operation on elasticsearch document field, means field having unique list of values. I am able to update document but facing duplicates issue.

```auto
//field value before update {"skills":["JAVA","HADOOP"]}
Map<String, String> params = ImmutableMap.of("skill", "JAVA");

client.prepareUpdate("index", "type", "id")
      .setScript(new Script("ctx._source.skills+=skill", ScriptService.ScriptType.INLINE, null, params))
      .get();

//field value after update {"skills":["JAVA","HADOOP","JAVA"]}
//expected field value after update without duplicates {"skills":["JAVA","HADOOP"]}

```

Can anybody please suggest if we have a way or must get previous value and have to re-construct then over-write it back.

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:16pm UTC](https://discuss.elastic.co/t/set-operations-on-elasticsearch-document-field/88712/2 "2017-07-06T12:16:44Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
