# Is there Any way to perform mongodb's $addToset like operation in elasticsearch while creating an document to elastic search

**URL:** <https://discuss.elastic.co/t/is-there-any-way-to-perform-mongodbs-addtoset-like-operation-in-elasticsearch-while-creating-an-document-to-elastic-search/86246>\
**Category:** Elasticsearch\
**Created:** [May 18, 2017, 11:47am UTC](https://discuss.elastic.co/t/is-there-any-way-to-perform-mongodbs-addtoset-like-operation-in-elasticsearch-while-creating-an-document-to-elastic-search/86246 "2017-05-18T11:47:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NavalKK](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@NavalKK](https://discuss.elastic.co/u/NavalKK)\
**Post date:** [May 18, 2017, 11:47am UTC](https://discuss.elastic.co/t/is-there-any-way-to-perform-mongodbs-addtoset-like-operation-in-elasticsearch-while-creating-an-document-to-elastic-search/86246/1 "2017-05-18T11:47:24Z")

</div>

Like If there is document which is already existing it will add some value to a array field, and if it doesnt exist it will create a new\_one?  
Ex.:-

{  
'name': 'john doe',  
'age': 12,  
'books': ['x', 'y']  
}

now if a document with this name already exists the query should add books to books field or it should create a new one

---

<div class="post-metadata">

**Author:** ![NavalKK](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@NavalKK](https://discuss.elastic.co/u/NavalKK)\
**Post date:** [May 18, 2017, 12:02pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-perform-mongodbs-addtoset-like-operation-in-elasticsearch-while-creating-an-document-to-elastic-search/86246/2 "2017-05-18T12:02:21Z")

</div>

Hey! I found my answer in official documentation.

---

<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:** [June 15, 2017, 12:02pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-perform-mongodbs-addtoset-like-operation-in-elasticsearch-while-creating-an-document-to-elastic-search/86246/3 "2017-06-15T12:02:27Z")

</div>

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