# Addition/Deletion Operation on Nested Documents

**URL:** <https://discuss.elastic.co/t/addition-deletion-operation-on-nested-documents/9060>\
**Category:** Elasticsearch\
**Created:** [September 19, 2012, 5:10am UTC](https://discuss.elastic.co/t/addition-deletion-operation-on-nested-documents/9060 "2012-09-19T05:10:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepak\_Chezhian](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@Deepak\_Chezhian](https://discuss.elastic.co/u/Deepak_Chezhian)\
**Post date:** [September 19, 2012, 5:10am UTC](https://discuss.elastic.co/t/addition-deletion-operation-on-nested-documents/9060/1 "2012-09-19T05:10:57Z")

</div>

Hi,

I have an use case in which i am often adding or removing the nested  
documents but there is no change in the parent document. Is it possible to  
do Add or Remove nested documents without re-indexing the whole parent  
document?

Regards,  
Deepak

--

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [September 19, 2012, 7:31am UTC](https://discuss.elastic.co/t/addition-deletion-operation-on-nested-documents/9060/2 "2012-09-19T07:31:38Z")

</div>

Simple answer: no

I think it would be theoretically possible to delete the nested document at  
the Lucene level but elasticsearch does not have API for that.

Lukas  
Dne 19.9.2012 7:10 "Deepak Chezhian" [cdeepakcse@gmail.com](mailto:cdeepakcse@gmail.com) napsal(a):

> Hi,
> 
> I have an use case in which i am often adding or removing the nested  
> documents but there is no change in the parent document. Is it possible to  
> do Add or Remove nested documents without re-indexing the whole parent  
> document?
> 
> Regards,  
> Deepak
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [September 19, 2012, 7:35am UTC](https://discuss.elastic.co/t/addition-deletion-operation-on-nested-documents/9060/3 "2012-09-19T07:35:33Z")

</div>

BTW: if you did not disable \_source you might want to look at Update API,  
it does reindexing for you but gives you an elegant shortcut for that.  
Dne 19.9.2012 9:31 "Lukáš Vlček" [lukas.vlcek@gmail.com](mailto:lukas.vlcek@gmail.com) napsal(a):

> Simple answer: no
> 
> I think it would be theoretically possible to delete the nested document  
> at the Lucene level but elasticsearch does not have API for that.
> 
> Lukas  
> Dne 19.9.2012 7:10 "Deepak Chezhian" [cdeepakcse@gmail.com](mailto:cdeepakcse@gmail.com) napsal(a):
> 
> > Hi,
> > 
> > I have an use case in which i am often adding or removing the nested  
> > documents but there is no change in the parent document. Is it possible to  
> > do Add or Remove nested documents without re-indexing the whole parent  
> > document?
> > 
> > Regards,  
> > Deepak
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![Deepak\_Chezhian](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@Deepak\_Chezhian](https://discuss.elastic.co/u/Deepak_Chezhian)\
**Post date:** [September 19, 2012, 11:24am UTC](https://discuss.elastic.co/t/addition-deletion-operation-on-nested-documents/9060/4 "2012-09-19T11:24:12Z")

</div>

Hi Lukas,

I tried update api with scripting, am able to add nested document but am  
not able to remove the existing documents.

I have used the examples in the following url for creating index and  
documents.

> <https://gist.github.com/lukas-vlcek/3739469>

For Addition, i have tried the following query. It worked.

{  
"script" : "ctx.\_source.works += work",  
"params" : {  
"work" : {  
"title" : "dad",  
"current" : true  
}  
}  
}

For removal, i have used the following query but it doesnt work.

{  
"script" : "ctx.\_source.works -= work",  
"params" : {  
"work" : {  
"title" : "dad",  
"current" : true  
}  
}  
}

Is there any other way of adding or removing documents from the nested  
documents using update api.

Regards,  
Deepak

On Wednesday, 19 September 2012 11:35:36 UTC+4, Lukáš Vlček wrote:

> BTW: if you did not disable \_source you might want to look at Update API,  
> it does reindexing for you but gives you an elegant shortcut for that.  
> Dne 19.9.2012 9:31 "Lukáš Vlček" \<[lukas...@gmail.com](mailto:lukas...@gmail.com) \<javascript:\>\>  
> napsal(a):
> 
> > Simple answer: no
> > 
> > I think it would be theoretically possible to delete the nested document  
> > at the Lucene level but elasticsearch does not have API for that.
> > 
> > Lukas  
> > Dne 19.9.2012 7:10 "Deepak Chezhian" \<[cdeep...@gmail.com](mailto:cdeep...@gmail.com) \<javascript:\>\>  
> > napsal(a):
> > 
> > > Hi,
> > > 
> > > I have an use case in which i am often adding or removing the nested  
> > > documents but there is no change in the parent document. Is it possible to  
> > > do Add or Remove nested documents without re-indexing the whole parent  
> > > document?
> > > 
> > > Regards,  
> > > Deepak
> > > 
> > > --

--

---

<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, 3:12am UTC](https://discuss.elastic.co/t/addition-deletion-operation-on-nested-documents/9060/5 "2017-07-06T03:12:21Z")

</div>


