# Is it possible to delete a subset of fields from a given document?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-delete-a-subset-of-fields-from-a-given-document/6740>\
**Category:** Elasticsearch\
**Created:** [February 17, 2012, 9:04pm UTC](https://discuss.elastic.co/t/is-it-possible-to-delete-a-subset-of-fields-from-a-given-document/6740 "2012-02-17T21:04:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![T\_Vinod\_Gupta](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@T\_Vinod\_Gupta](https://discuss.elastic.co/u/T_Vinod_Gupta)\
**Post date:** [February 17, 2012, 9:04pm UTC](https://discuss.elastic.co/t/is-it-possible-to-delete-a-subset-of-fields-from-a-given-document/6740/1 "2012-02-17T21:04:56Z")

</div>

lets say when i create a document, i have fields "a", "b" and "c"'. later i  
want to retrieve the document(s) and completely clear off fields "b" and  
"c". is it possible to do so?  
or do i need to delete the document and create a new one with the same id  
and just 1 field - "a"?

thanks

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [February 17, 2012, 9:48pm UTC](https://discuss.elastic.co/t/is-it-possible-to-delete-a-subset-of-fields-from-a-given-document/6740/2 "2012-02-17T21:48:18Z")

</div>

It is not possible to delete fields from a document in the index. You  
would need to reindex the document, which is standard in Lucene. The  
latest version of ES has the capability to update a field based on a  
script (which reindexes behind the scenes), but not delete a field.

You can always return only the relevant fields from a search by  
requesting only the fields you want.

--  
Ivan

On Fri, Feb 17, 2012 at 1:04 PM, T Vinod Gupta [tvinod@readypulse.com](mailto:tvinod@readypulse.com) wrote:

> lets say when i create a document, i have fields "a", "b" and "c"'. later i  
> want to retrieve the document(s) and completely clear off fields "b" and  
> "c". is it possible to do so?  
> or do i need to delete the document and create a new one with the same id  
> and just 1 field - "a"?
> 
> thanks

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 19, 2012, 12:50pm UTC](https://discuss.elastic.co/t/is-it-possible-to-delete-a-subset-of-fields-from-a-given-document/6740/3 "2012-02-19T12:50:47Z")

</div>

You can simply get the document, clear the fields, and index it again. You can use versioning to make sure no updates has happening while you were getting the document and updating the data.

0.19 has an update API that can be used remove the need of roundtrip of getting the doc and updating it.

On Friday, February 17, 2012 at 11:48 PM, Ivan Brusic wrote:

> It is not possible to delete fields from a document in the index. You  
> would need to reindex the document, which is standard in Lucene. The  
> latest version of ES has the capability to update a field based on a  
> script (which reindexes behind the scenes), but not delete a field.
> 
> You can always return only the relevant fields from a search by  
> requesting only the fields you want.
> 
> --  
> Ivan
> 
> On Fri, Feb 17, 2012 at 1:04 PM, T Vinod Gupta \<[tvinod@readypulse.com](mailto:tvinod@readypulse.com) ([mailto:tvinod@readypulse.com](mailto:tvinod@readypulse.com))\> wrote:
> 
> > lets say when i create a document, i have fields "a", "b" and "c"'. later i  
> > want to retrieve the document(s) and completely clear off fields "b" and  
> > "c". is it possible to do so?  
> > or do i need to delete the document and create a new one with the same id  
> > and just 1 field - "a"?
> > 
> > thanks

---

<div class="post-metadata">

**Author:** ![T\_Vinod\_Gupta](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@T\_Vinod\_Gupta](https://discuss.elastic.co/u/T_Vinod_Gupta)\
**Post date:** [February 19, 2012, 12:55pm UTC](https://discuss.elastic.co/t/is-it-possible-to-delete-a-subset-of-fields-from-a-given-document/6740/4 "2012-02-19T12:55:23Z")

</div>

thanks, that helps!

On Sun, Feb 19, 2012 at 4:50 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> You can simply get the document, clear the fields, and index it again.  
> You can use versioning to make sure no updates has happening while you were  
> getting the document and updating the data.
> 
> 0.19 has an update API that can be used remove the need of roundtrip of  
> getting the doc and updating it.
> 
> On Friday, February 17, 2012 at 11:48 PM, Ivan Brusic wrote:
> 
> It is not possible to delete fields from a document in the index. You  
> would need to reindex the document, which is standard in Lucene. The  
> latest version of ES has the capability to update a field based on a  
> script (which reindexes behind the scenes), but not delete a field.
> 
> You can always return only the relevant fields from a search by  
> requesting only the fields you want.
> 
> --  
> Ivan
> 
> On Fri, Feb 17, 2012 at 1:04 PM, T Vinod Gupta [tvinod@readypulse.com](mailto:tvinod@readypulse.com)  
> wrote:
> 
> lets say when i create a document, i have fields "a", "b" and "c"'. later i  
> want to retrieve the document(s) and completely clear off fields "b" and  
> "c". is it possible to do so?  
> or do i need to delete the document and create a new one with the same id  
> and just 1 field - "a"?
> 
> 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, 3:38am UTC](https://discuss.elastic.co/t/is-it-possible-to-delete-a-subset-of-fields-from-a-given-document/6740/5 "2017-07-06T03:38:50Z")

</div>


