# How to hide some fields in \_store using mappings

**URL:** <https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498>\
**Category:** Elasticsearch\
**Created:** [November 20, 2013, 4:39pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498 "2013-11-20T16:39:20Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![akram79](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@akram79](https://discuss.elastic.co/u/akram79)\
**Post date:** [November 20, 2013, 4:39pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/1 "2013-11-20T16:39:20Z")

</div>

Hi,

I have some data, which should be hidden/not displayed as part of the  
\_source.

when I set \_source : { enabled : false}, source is being returned as null.

How to make some fields are not displayed, but display \_source.

Regards,  
Akram.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![akram79](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@akram79](https://discuss.elastic.co/u/akram79)\
**Post date:** [November 20, 2013, 4:58pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/2 "2013-11-20T16:58:35Z")

</div>

On Wednesday, November 20, 2013 10:09:20 PM UTC+5:30, Akram Hussain wrote:

> Hi,
> 
> I have some data, which should be hidden/not displayed as part of the  
> \_source.
> 
> when I set \_source : { enabled : false}, source is being returned as null.
> 
> How to make some fields are not displayed, but display \_source.
> 
> Regards,  
> Akram.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [November 20, 2013, 4:58pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/3 "2013-11-20T16:58:54Z")

</div>

Elasticsearch does not modify the source, so you cannot change any part of  
it when it is stored. You can store individual fields and retrieve their  
value given the document. By default, elasticsearch does not store fields,  
which the requires having the source to retrieve the field values. So  
basically you can disable the source and enable storing only the fields you  
want. Look at the store option:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Keep in mind that you would need to retrieve each field individually, which  
means one seek per field, as opposed to one seek for the original document  
source. For a few fields, the difference is negligible, but might be an  
issue if you are using lots of stored fields.

Cheers,

Ivan

On Wed, Nov 20, 2013 at 8:39 AM, Akram Hussain  
[akram.hussain.sk@gmail.com](mailto:akram.hussain.sk@gmail.com)wrote:

> Hi,
> 
> I have some data, which should be hidden/not displayed as part of the  
> \_source.
> 
> when I set \_source : { enabled : false}, source is being returned as null.
> 
> How to make some fields are not displayed, but display \_source.
> 
> Regards,  
> Akram.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![akram79](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@akram79](https://discuss.elastic.co/u/akram79)\
**Post date:** [November 20, 2013, 5:11pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/4 "2013-11-20T17:11:23Z")

</div>

Hi Ivan,

Thanks for reply.

Can you let me know, how to retrieve each field using JAVA API and also I  
need to add some of the fields at runtime to \_source using java API. If  
possible can you please let me know, how to achieve it.

Regards,  
Akram.

On Wednesday, November 20, 2013 10:28:54 PM UTC+5:30, Ivan Brusic wrote:

> Elasticsearch does not modify the source, so you cannot change any part of  
> it when it is stored. You can store individual fields and retrieve their  
> value given the document. By default, elasticsearch does not store fields,  
> which the requires having the source to retrieve the field values. So  
> basically you can disable the source and enable storing only the fields you  
> want. Look at the store option:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html)
> 
> Keep in mind that you would need to retrieve each field individually,  
> which means one seek per field, as opposed to one seek for the original  
> document source. For a few fields, the difference is negligible, but might  
> be an issue if you are using lots of stored fields.
> 
> Cheers,
> 
> Ivan
> 
> On Wed, Nov 20, 2013 at 8:39 AM, Akram Hussain \<[akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > I have some data, which should be hidden/not displayed as part of the  
> > \_source.
> > 
> > when I set \_source : { enabled : false}, source is being returned as null.
> > 
> > How to make some fields are not displayed, but display \_source.
> > 
> > Regards,  
> > Akram.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [November 20, 2013, 5:57pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/5 "2013-11-20T17:57:48Z")

</div>

Hello Akram,

In the future, please respond to the mailing list and not back to whoever  
responded to you since there are others that can help and perhaps others in  
the future with the same issue can read the replies. Also please note that  
you sent three emails to the list and then two directly to me in a very  
short time span. This action is incredibly rude. Please do not spam.

After retrieve the SearchHits from the SearchResponse object, you can use  
the various field methods:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/search/SearchHit.java?source=cc#L142-L154](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/search/SearchHit.java?source=cc#L142-L154)

To add fields to an existing document, you can either reindex or use the  
update API:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

There is no Java API documentation, but the best way to explore how the  
Java API works is via the unit tests. Here are some tests for the update  
API:  
[https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/update/UpdateTests.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/update/UpdateTests.java)

Cheers,

Ivan

On Wed, Nov 20, 2013 at 9:11 AM, Akram Hussain  
[akram.hussain.sk@gmail.com](mailto:akram.hussain.sk@gmail.com)wrote:

> Hi Ivan,
> 
> Thanks for reply.
> 
> Can you let me know, how to retrieve each field using JAVA API and also I  
> need to add some of the fields at runtime to \_source using java API. If  
> possible can you please let me know, how to achieve it.
> 
> Regards,  
> Akram.
> 
> On Wednesday, November 20, 2013 10:28:54 PM UTC+5:30, Ivan Brusic wrote:
> 
> > Elasticsearch does not modify the source, so you cannot change any part  
> > of it when it is stored. You can store individual fields and retrieve  
> > their value given the document. By default, elasticsearch does not store  
> > fields, which the requires having the source to retrieve the field values.  
> > So basically you can disable the source and enable storing only the fields  
> > you want. Look at the store option:
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > reference/current/mapping-core-types.html
> > 
> > Keep in mind that you would need to retrieve each field individually,  
> > which means one seek per field, as opposed to one seek for the original  
> > document source. For a few fields, the difference is negligible, but might  
> > be an issue if you are using lots of stored fields.
> > 
> > Cheers,
> > 
> > Ivan
> > 
> > On Wed, Nov 20, 2013 at 8:39 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > 
> > > Hi,
> > > 
> > > I have some data, which should be hidden/not displayed as part of the  
> > > \_source.
> > > 
> > > when I set \_source : { enabled : false}, source is being returned as  
> > > null.
> > > 
> > > How to make some fields are not displayed, but display \_source.
> > > 
> > > Regards,  
> > > Akram.
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![akram79](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@akram79](https://discuss.elastic.co/u/akram79)\
**Post date:** [November 21, 2013, 6:44am UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/6 "2013-11-21T06:44:05Z")

</div>

Hi Ivan,

I was not properly aware of this UI, so I followed usual, gmail with reply  
to Author button.

Sorry for Inconvenience.

* * *

Still I have some doubts on query posted.

When I set \_source : {"enabled" : false}, I am not able to get value of  
fields, If I try to get each field individually by  
searchHit.getField("fieldName"). As I looked into the method getField it  
internally fetching from source map only, where it is null.

Do I have any other options to get the field values.

Regards,  
Akram.

On Wednesday, November 20, 2013 11:27:48 PM UTC+5:30, Ivan Brusic wrote:

> Hello Akram,
> 
> In the future, please respond to the mailing list and not back to whoever  
> responded to you since there are others that can help and perhaps others in  
> the future with the same issue can read the replies. Also please note that  
> you sent three emails to the list and then two directly to me in a very  
> short time span. This action is incredibly rude. Please do not spam.
> 
> After retrieve the SearchHits from the SearchResponse object, you can use  
> the various field methods:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.html)
> 
> [https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/search/SearchHit.java?source=cc#L142-L154](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/search/SearchHit.java?source=cc#L142-L154)
> 
> To add fields to an existing document, you can either reindex or use the  
> update API:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-update.html)
> 
> There is no Java API documentation, but the best way to explore how the  
> Java API works is via the unit tests. Here are some tests for the update  
> API:
> 
> [https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/update/UpdateTests.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/update/UpdateTests.java)
> 
> Cheers,
> 
> Ivan
> 
> On Wed, Nov 20, 2013 at 9:11 AM, Akram Hussain \<[akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi Ivan,
> > 
> > Thanks for reply.
> > 
> > Can you let me know, how to retrieve each field using JAVA API and also I  
> > need to add some of the fields at runtime to \_source using java API. If  
> > possible can you please let me know, how to achieve it.
> > 
> > Regards,  
> > Akram.
> > 
> > On Wednesday, November 20, 2013 10:28:54 PM UTC+5:30, Ivan Brusic wrote:
> > 
> > > Elasticsearch does not modify the source, so you cannot change any part  
> > > of it when it is stored. You can store individual fields and retrieve  
> > > their value given the document. By default, elasticsearch does not store  
> > > fields, which the requires having the source to retrieve the field values.  
> > > So basically you can disable the source and enable storing only the fields  
> > > you want. Look at the store option:
> > > 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > > reference/current/mapping-core-types.html
> > > 
> > > Keep in mind that you would need to retrieve each field individually,  
> > > which means one seek per field, as opposed to one seek for the original  
> > > document source. For a few fields, the difference is negligible, but might  
> > > be an issue if you are using lots of stored fields.
> > > 
> > > Cheers,
> > > 
> > > Ivan
> > > 
> > > On Wed, Nov 20, 2013 at 8:39 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I have some data, which should be hidden/not displayed as part of the  
> > > > \_source.
> > > > 
> > > > when I set \_source : { enabled : false}, source is being returned as  
> > > > null.
> > > > 
> > > > How to make some fields are not displayed, but display \_source.
> > > > 
> > > > Regards,  
> > > > Akram.
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > 
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Hannes\_Korte](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hannes_korte/32/909_2.png) [@Hannes\_Korte](https://discuss.elastic.co/u/Hannes_Korte)\
**Post date:** [November 21, 2013, 8:28am UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/7 "2013-11-21T08:28:39Z")

</div>

Hi Akram,

besides the solution of storing each field individually, you could as  
well include and exclude certain fields in the source:

"\_source" : {  
"includes" : ["timestamp", "title", "tinyfields._"],  
"excludes" : ["largefields._"]  
}

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Best regards,  
Hannes

On 20.11.2013 17:39, Akram Hussain wrote:

> Hi,
> 
> I have some data, which should be hidden/not displayed as part of the  
> \_source.
> 
> when I set \_source : { enabled : false}, source is being returned as null.
> 
> How to make some fields are not displayed, but display \_source.
> 
> Regards,  
> Akram.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![akram79](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@akram79](https://discuss.elastic.co/u/akram79)\
**Post date:** [November 21, 2013, 12:57pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/8 "2013-11-21T12:57:01Z")

</div>

Hi,

Thanks for the reply.

It worked, but failed when try to add some other new fields to the source  
from java api.

I have template like this

"mappings" : {  
"_default_" : {  
"\_source" : {  
"includes": ["\*"],  
"excludes": ["data"]  
}  
}  
}

where only data field should be hidden, but it should be searchable.

1. With the template I have created the doc like {"data" : "dataone",  
"config": "config data", "status": "fine"}.
2. When I searched for "dataone" using java api, it returned the correct  
data, with remaining fields displayed not displaying "data" field - _it is  
fine_.
3. To the ssme document added some other fields like "assigned", etc - They  
were added to document.
4. But when I searched once again for "dataone" using java api, now the  
search is not returning the data.

how to make "data" field, should not be lost after updated - I guess it  
lost but not sure, but not returning in the search result at second time).

Regards,  
Akram.

On Thursday, November 21, 2013 1:58:39 PM UTC+5:30, Hannes Korte wrote:

> Hi Akram,
> 
> besides the solution of storing each field individually, you could as  
> well include and exclude certain fields in the source:
> 
> "\_source" : {  
> "includes" : ["timestamp", "title", "tinyfields._"],  
> "excludes" : ["largefields._"]  
> }
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-source-field.html)
> 
> Best regards,  
> Hannes
> 
> On 20.11.2013 17:39, Akram Hussain wrote:
> 
> > Hi,
> > 
> > I have some data, which should be hidden/not displayed as part of the  
> > \_source.
> > 
> > when I set \_source : { enabled : false}, source is being returned as  
> > null.
> > 
> > How to make some fields are not displayed, but display \_source.
> > 
> > Regards,  
> > Akram.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [November 21, 2013, 5:58pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/9 "2013-11-21T17:58:58Z")

</div>

It would help if you provided your mapping and an example query. Are you  
searching against a certain field, the data field, or the \_all field?  
Create a gist as described here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/) It  
would help to retrieve the current mapping via the API, because some times  
the mapping that is in effect might not be identical to the one you  
supplied. 🙂

One issue to point out, in case it was not understood, is that some updates  
to the mapping will not affect documents that are currently indexed. How  
are you adding fields to a document? Are you reindexing or using the update  
API?

Cheers,

Ivan

On Thu, Nov 21, 2013 at 4:57 AM, Akram Hussain  
[akram.hussain.sk@gmail.com](mailto:akram.hussain.sk@gmail.com)wrote:

> Hi,
> 
> Thanks for the reply.
> 
> It worked, but failed when try to add some other new fields to the source  
> from java api.
> 
> I have template like this
> 
> "mappings" : {  
> "_default_" : {  
> "\_source" : {  
> "includes": ["\*"],  
> "excludes": ["data"]  
> }  
> }  
> }
> 
> where only data field should be hidden, but it should be searchable.
> 
> 1. With the template I have created the doc like {"data" : "dataone",  
> "config": "config data", "status": "fine"}.
> 2. When I searched for "dataone" using java api, it returned the correct  
> data, with remaining fields displayed not displaying "data" field - _it  
> is fine_.
> 3. To the ssme document added some other fields like "assigned", etc -  
> They were added to document.
> 4. But when I searched once again for "dataone" using java api, now the  
> search is not returning the data.
> 
> how to make "data" field, should not be lost after updated - I guess it  
> lost but not sure, but not returning in the search result at second time).
> 
> Regards,  
> Akram.
> 
> On Thursday, November 21, 2013 1:58:39 PM UTC+5:30, Hannes Korte wrote:
> 
> > Hi Akram,
> > 
> > besides the solution of storing each field individually, you could as  
> > well include and exclude certain fields in the source:
> > 
> > "\_source" : {  
> > "includes" : ["timestamp", "title", "tinyfields._"],  
> > "excludes" : ["largefields._"]  
> > }
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > reference/current/mapping-source-field.html
> > 
> > Best regards,  
> > Hannes
> > 
> > On 20.11.2013 17:39, Akram Hussain wrote:
> > 
> > > Hi,
> > > 
> > > I have some data, which should be hidden/not displayed as part of the  
> > > \_source.
> > > 
> > > when I set \_source : { enabled : false}, source is being returned as  
> > > null.
> > > 
> > > How to make some fields are not displayed, but display \_source.
> > > 
> > > Regards,  
> > > Akram.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![akram79](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@akram79](https://discuss.elastic.co/u/akram79)\
**Post date:** [November 22, 2013, 4:21am UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/10 "2013-11-22T04:21:48Z")

</div>

Hi,

The following one is my template

_{_

- "order\_template" : {\*
- "template" : "_",_
- "order": 0,\*
- "settings" :{\*
- },\*
- "mappings" : {\*
- "_default_" : {\*
- "\_source" : {\*
- "includes": ["_"],_
- "excludes": ["text"]\*
- }\*
- }\*
- }\*
- }\*  
_}_

I am fetching the results using

_SearchRequestBuilder builder =  
client.prepareSearch(searchContext.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)_

- .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());\*  
_builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuilders.queryFilter(queryBuilder)));_

but updating is being done by following api

_StringBuilder scriptBuilder = new StringBuilder();_  
_scriptBuilder.append("ctx.\_source.").append("assigned").append("=").append("value");_  
_client.prepareUpdate(index, type, id).setScript(scriptBuilder.toString());_

after updating with above api, the hidden field, i.e, \*data \*field is lost.

I am doing any thing wrong while using api's.

Regards  
Akram.

On Thursday, November 21, 2013 11:28:58 PM UTC+5:30, Ivan Brusic wrote:

> It would help if you provided your mapping and an example query. Are you  
> searching against a certain field, the data field, or the \_all field?  
> Create a gist as described here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/)[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5\_ert12o9OPxq7NdLYIOQ5Nig](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5_ert12o9OPxq7NdLYIOQ5Nig) It  
> would help to retrieve the current mapping via the API, because some times  
> the mapping that is in effect might not be identical to the one you  
> supplied. 🙂
> 
> One issue to point out, in case it was not understood, is that some  
> updates to the mapping will not affect documents that are currently  
> indexed. How are you adding fields to a document? Are you reindexing or  
> using the update API?
> 
> Cheers,
> 
> Ivan
> 
> On Thu, Nov 21, 2013 at 4:57 AM, Akram Hussain \<[akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > Thanks for the reply.
> > 
> > It worked, but failed when try to add some other new fields to the source  
> > from java api.
> > 
> > I have template like this
> > 
> > "mappings" : {  
> > "_default_" : {  
> > "\_source" : {  
> > "includes": ["\*"],  
> > "excludes": ["data"]  
> > }  
> > }  
> > }
> > 
> > where only data field should be hidden, but it should be searchable.
> > 
> > 1. With the template I have created the doc like {"data" : "dataone",  
> > "config": "config data", "status": "fine"}.
> > 2. When I searched for "dataone" using java api, it returned the correct  
> > data, with remaining fields displayed not displaying "data" field - _it  
> > is fine_.
> > 3. To the ssme document added some other fields like "assigned", etc -  
> > They were added to document.
> > 4. But when I searched once again for "dataone" using java api, now the  
> > search is not returning the data.
> > 
> > how to make "data" field, should not be lost after updated - I guess it  
> > lost but not sure, but not returning in the search result at second time).
> > 
> > Regards,  
> > Akram.
> > 
> > On Thursday, November 21, 2013 1:58:39 PM UTC+5:30, Hannes Korte wrote:
> > 
> > > Hi Akram,
> > > 
> > > besides the solution of storing each field individually, you could as  
> > > well include and exclude certain fields in the source:
> > > 
> > > "\_source" : {  
> > > "includes" : ["timestamp", "title", "tinyfields._"],  
> > > "excludes" : ["largefields._"]  
> > > }
> > > 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > > reference/current/mapping-source-field.html[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA)
> > > 
> > > Best regards,  
> > > Hannes
> > > 
> > > On 20.11.2013 17:39, Akram Hussain wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I have some data, which should be hidden/not displayed as part of the  
> > > > \_source.
> > > > 
> > > > when I set \_source : { enabled : false}, source is being returned as  
> > > > null.
> > > > 
> > > > How to make some fields are not displayed, but display \_source.
> > > > 
> > > > Regards,  
> > > > Akram.
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [November 22, 2013, 5:44pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/11 "2013-11-22T17:44:36Z")

</div>

In your query code, you posted everything except the actual query! Which  
field are you searching against? You mention that the data field is lost,  
but you are excluding the text field. Typo?

I never exclude fields in source, but it seems like a field is required if  
you want to search against it. It works after indexing, but will disappear  
after updating. I doubt that is a bug, since elasticsearch has nothing to  
update. An update basically is an atomic delete/insert.

Cheers,

Ivan

On Thu, Nov 21, 2013 at 8:21 PM, Akram Hussain  
[akram.hussain.sk@gmail.com](mailto:akram.hussain.sk@gmail.com)wrote:

> Hi,
> 
> The following one is my template
> 
> _{_
> 
> - "order\_template" : {\*
> - "template" : "_",_
> - "order": 0,\*
> - "settings" :{\*
> - },\*
> - "mappings" : {\*
> - "_default_" : {\*
> - "\_source" : {\*
> - "includes": ["_"],_
> - "excludes": ["text"]\*
> - }\*
> - }\*
> - }\*
> - }\*  
> _}_
> 
> I am fetching the results using
> 
> _SearchRequestBuilder builder =  
> client.prepareSearch(searchContext.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)_
> 
> - .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());\*
> 
> _builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuilders.queryFilter(queryBuilder)));_
> 
> but updating is being done by following api
> 
> _StringBuilder scriptBuilder = new StringBuilder();_
> 
> _scriptBuilder.append("ctx.\_source.").append("assigned").append("=").append("value");_  
> _client.prepareUpdate(index, type,  
> id).setScript(scriptBuilder.toString());_
> 
> after updating with above api, the hidden field, i.e, \*data \*field is  
> lost.
> 
> I am doing any thing wrong while using api's.
> 
> Regards  
> Akram.
> 
> On Thursday, November 21, 2013 11:28:58 PM UTC+5:30, Ivan Brusic wrote:
> 
> > It would help if you provided your mapping and an example query. Are you  
> > searching against a certain field, the data field, or the \_all field?  
> > Create a gist as described here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/)[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5\_ert12o9OPxq7NdLYIOQ5Nig](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5_ert12o9OPxq7NdLYIOQ5Nig) It  
> > would help to retrieve the current mapping via the API, because some times  
> > the mapping that is in effect might not be identical to the one you  
> > supplied. 🙂
> > 
> > One issue to point out, in case it was not understood, is that some  
> > updates to the mapping will not affect documents that are currently  
> > indexed. How are you adding fields to a document? Are you reindexing or  
> > using the update API?
> > 
> > Cheers,
> > 
> > Ivan
> > 
> > On Thu, Nov 21, 2013 at 4:57 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > 
> > > Hi,
> > > 
> > > Thanks for the reply.
> > > 
> > > It worked, but failed when try to add some other new fields to the  
> > > source from java api.
> > > 
> > > I have template like this
> > > 
> > > "mappings" : {  
> > > "_default_" : {  
> > > "\_source" : {  
> > > "includes": ["\*"],  
> > > "excludes": ["data"]  
> > > }  
> > > }  
> > > }
> > > 
> > > where only data field should be hidden, but it should be searchable.
> > > 
> > > 1. With the template I have created the doc like {"data" : "dataone",  
> > > "config": "config data", "status": "fine"}.
> > > 2. When I searched for "dataone" using java api, it returned the correct  
> > > data, with remaining fields displayed not displaying "data" field - _it  
> > > is fine_.
> > > 3. To the ssme document added some other fields like "assigned", etc -  
> > > They were added to document.
> > > 4. But when I searched once again for "dataone" using java api, now the  
> > > search is not returning the data.
> > > 
> > > how to make "data" field, should not be lost after updated - I guess it  
> > > lost but not sure, but not returning in the search result at second time).
> > > 
> > > Regards,  
> > > Akram.
> > > 
> > > On Thursday, November 21, 2013 1:58:39 PM UTC+5:30, Hannes Korte wrote:
> > > 
> > > > Hi Akram,
> > > > 
> > > > besides the solution of storing each field individually, you could as  
> > > > well include and exclude certain fields in the source:
> > > > 
> > > > "\_source" : {  
> > > > "includes" : ["timestamp", "title", "tinyfields._"],  
> > > > "excludes" : ["largefields._"]  
> > > > }
> > > > 
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/referenc)  
> > > > e/current/mapping-source-field.html[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA)
> > > > 
> > > > Best regards,  
> > > > Hannes
> > > > 
> > > > On 20.11.2013 17:39, Akram Hussain wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > I have some data, which should be hidden/not displayed as part of the  
> > > > > \_source.
> > > > > 
> > > > > when I set \_source : { enabled : false}, source is being returned as  
> > > > > null.
> > > > > 
> > > > > How to make some fields are not displayed, but display \_source.
> > > > > 
> > > > > Regards,  
> > > > > Akram.
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![akram79](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@akram79](https://discuss.elastic.co/u/akram79)\
**Post date:** [November 22, 2013, 5:55pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/12 "2013-11-22T17:55:49Z")

</div>

Hi,

yes, I have missed the line, the code is, as it was returned from other  
method, I missed it.

SearchRequestBuilder builder =  
client.prepareSearch(searchContext.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
.setFrom(searchContext.getOffset()).setSize(searchContext.getSize());  
_QueryBuilder queryBuilder = QueryBuilders.matchPhrasePrefixQuery("data",  
"dataValue");_  
builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuilders.queryFilter(queryBuilder)));

The missed line is the bold line, it will search on "data" field itself,  
after updating/adding new fields to the source, the field "data" is getting  
lost from source.

Let me know the possible ways to handle it.

Regards,  
Akram.

On Friday, November 22, 2013 11:14:36 PM UTC+5:30, Ivan Brusic wrote:

> In your query code, you posted everything except the actual query! Which  
> field are you searching against? You mention that the data field is lost,  
> but you are excluding the text field. Typo?
> 
> I never exclude fields in source, but it seems like a field is required if  
> you want to search against it. It works after indexing, but will disappear  
> after updating. I doubt that is a bug, since elasticsearch has nothing to  
> update. An update basically is an atomic delete/insert.
> 
> Cheers,
> 
> Ivan
> 
> On Thu, Nov 21, 2013 at 8:21 PM, Akram Hussain \<[akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > The following one is my template
> > 
> > _{_
> > 
> > - "order\_template" : {\*
> > - "template" : "_",_
> > - "order": 0,\*
> > - "settings" :{\*
> > - },\*
> > - "mappings" : {\*
> > - "_default_" : {\*
> > - "\_source" : {\*
> > - "includes": ["_"],_
> > - "excludes": ["text"]\*
> > - }\*
> > - }\*
> > - }\*
> > - }\*  
> > _}_
> > 
> > I am fetching the results using
> > 
> > _SearchRequestBuilder builder =  
> > client.prepareSearch(searchContext.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)_
> > 
> > - .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());\*
> > 
> > _builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuilders.queryFilter(queryBuilder)));_
> > 
> > but updating is being done by following api
> > 
> > _StringBuilder scriptBuilder = new StringBuilder();_
> > 
> > _scriptBuilder.append("ctx.\_source.").append("assigned").append("=").append("value");_  
> > _client.prepareUpdate(index, type,  
> > id).setScript(scriptBuilder.toString());_
> > 
> > after updating with above api, the hidden field, i.e, \*data \*field is  
> > lost.
> > 
> > I am doing any thing wrong while using api's.
> > 
> > Regards  
> > Akram.
> > 
> > On Thursday, November 21, 2013 11:28:58 PM UTC+5:30, Ivan Brusic wrote:
> > 
> > > It would help if you provided your mapping and an example query. Are you  
> > > searching against a certain field, the data field, or the \_all field?  
> > > Create a gist as described here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/)[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNGgo5\_ert12o9OPxq7NdLYIOQ5Nig](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNGgo5_ert12o9OPxq7NdLYIOQ5Nig) It  
> > > would help to retrieve the current mapping via the API, because some times  
> > > the mapping that is in effect might not be identical to the one you  
> > > supplied. 🙂
> > > 
> > > One issue to point out, in case it was not understood, is that some  
> > > updates to the mapping will not affect documents that are currently  
> > > indexed. How are you adding fields to a document? Are you reindexing or  
> > > using the update API?
> > > 
> > > Cheers,
> > > 
> > > Ivan
> > > 
> > > On Thu, Nov 21, 2013 at 4:57 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > > 
> > > > Hi,
> > > > 
> > > > Thanks for the reply.
> > > > 
> > > > It worked, but failed when try to add some other new fields to the  
> > > > source from java api.
> > > > 
> > > > I have template like this
> > > > 
> > > > "mappings" : {  
> > > > "_default_" : {  
> > > > "\_source" : {  
> > > > "includes": ["\*"],  
> > > > "excludes": ["data"]  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > where only data field should be hidden, but it should be searchable.
> > > > 
> > > > 1. With the template I have created the doc like {"data" : "dataone",  
> > > > "config": "config data", "status": "fine"}.
> > > > 2. When I searched for "dataone" using java api, it returned the  
> > > > correct data, with remaining fields displayed not displaying "data" field - _it  
> > > > is fine_.
> > > > 3. To the ssme document added some other fields like "assigned", etc -  
> > > > They were added to document.
> > > > 4. But when I searched once again for "dataone" using java api, now the  
> > > > search is not returning the data.
> > > > 
> > > > how to make "data" field, should not be lost after updated - I guess it  
> > > > lost but not sure, but not returning in the search result at second time).
> > > > 
> > > > Regards,  
> > > > Akram.
> > > > 
> > > > On Thursday, November 21, 2013 1:58:39 PM UTC+5:30, Hannes Korte wrote:
> > > > 
> > > > > Hi Akram,
> > > > > 
> > > > > besides the solution of storing each field individually, you could as  
> > > > > well include and exclude certain fields in the source:
> > > > > 
> > > > > "\_source" : {  
> > > > > "includes" : ["timestamp", "title", "tinyfields._"],  
> > > > > "excludes" : ["largefields._"]  
> > > > > }
> > > > > 
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/referenc)  
> > > > > e/current/mapping-source-field.html[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA)
> > > > > 
> > > > > Best regards,  
> > > > > Hannes
> > > > > 
> > > > > On 20.11.2013 17:39, Akram Hussain wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > I have some data, which should be hidden/not displayed as part of  
> > > > > > the  
> > > > > > \_source.
> > > > > > 
> > > > > > when I set \_source : { enabled : false}, source is being returned as  
> > > > > > null.
> > > > > > 
> > > > > > How to make some fields are not displayed, but display \_source.
> > > > > > 
> > > > > > Regards,  
> > > > > > Akram.
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > 
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [November 22, 2013, 6:00pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/13 "2013-11-22T18:00:33Z")

</div>

I do not see the issue on 0.90.5. After an update I can no longer search  
against the "text" field, but "data" works fine.

On Fri, Nov 22, 2013 at 9:55 AM, Akram Hussain  
[akram.hussain.sk@gmail.com](mailto:akram.hussain.sk@gmail.com)wrote:

> Hi,
> 
> yes, I have missed the line, the code is, as it was returned from other  
> method, I missed it.
> 
> SearchRequestBuilder builder = client.prepareSearch(  
> searchContext.getIndexName()).setSearchType(SearchType.DFS\_  
> QUERY\_THEN\_FETCH)  
> .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());  
> _QueryBuilder queryBuilder = QueryBuilders.matchPhrasePrefixQuery("data",  
> "dataValue");_  
> builder.setQuery(QueryBuilders.constantScoreQuery(  
> FilterBuilders.queryFilter(queryBuilder)));
> 
> The missed line is the bold line, it will search on "data" field itself,  
> after updating/adding new fields to the source, the field "data" is getting  
> lost from source.
> 
> Let me know the possible ways to handle it.
> 
> Regards,  
> Akram.
> 
> On Friday, November 22, 2013 11:14:36 PM UTC+5:30, Ivan Brusic wrote:
> 
> > In your query code, you posted everything except the actual query! Which  
> > field are you searching against? You mention that the data field is lost,  
> > but you are excluding the text field. Typo?
> > 
> > I never exclude fields in source, but it seems like a field is required  
> > if you want to search against it. It works after indexing, but will  
> > disappear after updating. I doubt that is a bug, since elasticsearch has  
> > nothing to update. An update basically is an atomic delete/insert.
> > 
> > Cheers,
> > 
> > Ivan
> > 
> > On Thu, Nov 21, 2013 at 8:21 PM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > 
> > > Hi,
> > > 
> > > The following one is my template
> > > 
> > > _{_
> > > 
> > > - "order\_template" : {\*
> > > - "template" : "_",_
> > > - "order": 0,\*
> > > - "settings" :{\*
> > > - },\*
> > > - "mappings" : {\*
> > > - "_default_" : {\*
> > > - "\_source" : {\*
> > > - "includes": ["_"],_
> > > - "excludes": ["text"]\*
> > > - }\*
> > > - }\*
> > > - }\*
> > > - }\*  
> > > _}_
> > > 
> > > I am fetching the results using
> > > 
> > > _SearchRequestBuilder builder =  
> > > client.prepareSearch(searchContext.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)_
> > > 
> > > - .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());\*
> > > 
> > > _builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuilders.queryFilter(queryBuilder)));_
> > > 
> > > but updating is being done by following api
> > > 
> > > _StringBuilder scriptBuilder = new StringBuilder();_
> > > 
> > > _scriptBuilder.append("ctx.\_source.").append("assigned").append("=").append("value");_  
> > > _client.prepareUpdate(index, type,  
> > > id).setScript(scriptBuilder.toString());_
> > > 
> > > after updating with above api, the hidden field, i.e, \*data \*field is  
> > > lost.
> > > 
> > > I am doing any thing wrong while using api's.
> > > 
> > > Regards  
> > > Akram.
> > > 
> > > On Thursday, November 21, 2013 11:28:58 PM UTC+5:30, Ivan Brusic wrote:
> > > 
> > > > It would help if you provided your mapping and an example query. Are  
> > > > you searching against a certain field, the data field, or the \_all field?  
> > > > Create a gist as described here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/)[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5\_ert12o9OPxq7NdLYIOQ5Nig](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5_ert12o9OPxq7NdLYIOQ5Nig) It  
> > > > would help to retrieve the current mapping via the API, because some times  
> > > > the mapping that is in effect might not be identical to the one you  
> > > > supplied. 🙂
> > > > 
> > > > One issue to point out, in case it was not understood, is that some  
> > > > updates to the mapping will not affect documents that are currently  
> > > > indexed. How are you adding fields to a document? Are you reindexing or  
> > > > using the update API?
> > > > 
> > > > Cheers,
> > > > 
> > > > Ivan
> > > > 
> > > > On Thu, Nov 21, 2013 at 4:57 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > Thanks for the reply.
> > > > > 
> > > > > It worked, but failed when try to add some other new fields to the  
> > > > > source from java api.
> > > > > 
> > > > > I have template like this
> > > > > 
> > > > > "mappings" : {  
> > > > > "_default_" : {  
> > > > > "\_source" : {  
> > > > > "includes": ["\*"],  
> > > > > "excludes": ["data"]  
> > > > > }  
> > > > > }  
> > > > > }
> > > > > 
> > > > > where only data field should be hidden, but it should be searchable.
> > > > > 
> > > > > 1. With the template I have created the doc like {"data" : "dataone",  
> > > > > "config": "config data", "status": "fine"}.
> > > > > 2. When I searched for "dataone" using java api, it returned the  
> > > > > correct data, with remaining fields displayed not displaying "data" field - _it  
> > > > > is fine_.
> > > > > 3. To the ssme document added some other fields like "assigned", etc -  
> > > > > They were added to document.
> > > > > 4. But when I searched once again for "dataone" using java api, now  
> > > > > the search is not returning the data.
> > > > > 
> > > > > how to make "data" field, should not be lost after updated - I guess  
> > > > > it lost but not sure, but not returning in the search result at second  
> > > > > time).
> > > > > 
> > > > > Regards,  
> > > > > Akram.
> > > > > 
> > > > > On Thursday, November 21, 2013 1:58:39 PM UTC+5:30, Hannes Korte wrote:
> > > > > 
> > > > > > Hi Akram,
> > > > > > 
> > > > > > besides the solution of storing each field individually, you could as  
> > > > > > well include and exclude certain fields in the source:
> > > > > > 
> > > > > > "\_source" : {  
> > > > > > "includes" : ["timestamp", "title", "tinyfields._"],  
> > > > > > "excludes" : ["largefields._"]  
> > > > > > }
> > > > > > 
> > > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/referenc)  
> > > > > > e/current/mapping-source-field.html[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA)
> > > > > > 
> > > > > > Best regards,  
> > > > > > Hannes
> > > > > > 
> > > > > > On 20.11.2013 17:39, Akram Hussain wrote:
> > > > > > 
> > > > > > > Hi,
> > > > > > > 
> > > > > > > I have some data, which should be hidden/not displayed as part of  
> > > > > > > the  
> > > > > > > \_source.
> > > > > > > 
> > > > > > > when I set \_source : { enabled : false}, source is being returned  
> > > > > > > as null.
> > > > > > > 
> > > > > > > How to make some fields are not displayed, but display \_source.
> > > > > > > 
> > > > > > > Regards,  
> > > > > > > Akram.
> > > > > > 
> > > > > > --  
> > > > > > You received this message because you are subscribed to the Google  
> > > > > > Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > 
> > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![akram79](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@akram79](https://discuss.elastic.co/u/akram79)\
**Post date:** [November 22, 2013, 6:19pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/14 "2013-11-22T18:19:45Z")

</div>

Hi,

I was my once again copy & paste mistake.

{  
"order\_template" : {  
"template" : "_",  
"order": 0,  
"settings" :{  
},  
"mappings" : {  
"default" : {  
"\_source" : {  
"includes": ["_"],  
"excludes": ["_data_"]  
}  
}  
}  
}  
}

it is the data field, which was in "excludes" list, able to search first  
time on the "data" field, but after updating, not able to search on the  
"data" field.

I am sorry, once again for the confusion.

Regards,  
Akram.

On Friday, November 22, 2013 11:30:33 PM UTC+5:30, Ivan Brusic wrote:

> I do not see the issue on 0.90.5. After an update I can no longer search  
> against the "text" field, but "data" works fine.
> 
> On Fri, Nov 22, 2013 at 9:55 AM, Akram Hussain \<[akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > yes, I have missed the line, the code is, as it was returned from other  
> > method, I missed it.
> > 
> > SearchRequestBuilder builder = client.prepareSearch(  
> > searchContext.getIndexName()).setSearchType(SearchType.DFS\_  
> > QUERY\_THEN\_FETCH)  
> > .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());  
> > _QueryBuilder queryBuilder = QueryBuilders.matchPhrasePrefixQuery("data",  
> > "dataValue");_  
> > builder.setQuery(QueryBuilders.constantScoreQuery(  
> > FilterBuilders.queryFilter(queryBuilder)));
> > 
> > The missed line is the bold line, it will search on "data" field itself,  
> > after updating/adding new fields to the source, the field "data" is getting  
> > lost from source.
> > 
> > Let me know the possible ways to handle it.
> > 
> > Regards,  
> > Akram.
> > 
> > On Friday, November 22, 2013 11:14:36 PM UTC+5:30, Ivan Brusic wrote:
> > 
> > > In your query code, you posted everything except the actual query! Which  
> > > field are you searching against? You mention that the data field is lost,  
> > > but you are excluding the text field. Typo?
> > > 
> > > I never exclude fields in source, but it seems like a field is required  
> > > if you want to search against it. It works after indexing, but will  
> > > disappear after updating. I doubt that is a bug, since elasticsearch has  
> > > nothing to update. An update basically is an atomic delete/insert.
> > > 
> > > Cheers,
> > > 
> > > Ivan
> > > 
> > > On Thu, Nov 21, 2013 at 8:21 PM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > > 
> > > > Hi,
> > > > 
> > > > The following one is my template
> > > > 
> > > > _{_
> > > > 
> > > > - "order\_template" : {\*
> > > > - "template" : "_",_
> > > > - "order": 0,\*
> > > > - "settings" :{\*
> > > > - },\*
> > > > - "mappings" : {\*
> > > > - "_default_" : {\*
> > > > - "\_source" : {\*
> > > > - "includes": ["_"],_
> > > > - "excludes": ["text"]\*
> > > > - }\*
> > > > - }\*
> > > > - }\*
> > > > - }\*  
> > > > _}_
> > > > 
> > > > I am fetching the results using
> > > > 
> > > > _SearchRequestBuilder builder =  
> > > > client.prepareSearch(searchContext.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)_
> > > > 
> > > > - .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());\*
> > > > 
> > > > _builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuilders.queryFilter(queryBuilder)));_
> > > > 
> > > > but updating is being done by following api
> > > > 
> > > > _StringBuilder scriptBuilder = new StringBuilder();_
> > > > 
> > > > _scriptBuilder.append("ctx.\_source.").append("assigned").append("=").append("value");_  
> > > > _client.prepareUpdate(index, type,  
> > > > id).setScript(scriptBuilder.toString());_
> > > > 
> > > > after updating with above api, the hidden field, i.e, \*data \*field is  
> > > > lost.
> > > > 
> > > > I am doing any thing wrong while using api's.
> > > > 
> > > > Regards  
> > > > Akram.
> > > > 
> > > > On Thursday, November 21, 2013 11:28:58 PM UTC+5:30, Ivan Brusic wrote:
> > > > 
> > > > > It would help if you provided your mapping and an example query. Are  
> > > > > you searching against a certain field, the data field, or the \_all field?  
> > > > > Create a gist as described here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/)[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNGgo5\_ert12o9OPxq7NdLYIOQ5Nig](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNGgo5_ert12o9OPxq7NdLYIOQ5Nig) It  
> > > > > would help to retrieve the current mapping via the API, because some times  
> > > > > the mapping that is in effect might not be identical to the one you  
> > > > > supplied. 🙂
> > > > > 
> > > > > One issue to point out, in case it was not understood, is that some  
> > > > > updates to the mapping will not affect documents that are currently  
> > > > > indexed. How are you adding fields to a document? Are you reindexing or  
> > > > > using the update API?
> > > > > 
> > > > > Cheers,
> > > > > 
> > > > > Ivan
> > > > > 
> > > > > On Thu, Nov 21, 2013 at 4:57 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > Thanks for the reply.
> > > > > > 
> > > > > > It worked, but failed when try to add some other new fields to the  
> > > > > > source from java api.
> > > > > > 
> > > > > > I have template like this
> > > > > > 
> > > > > > "mappings" : {  
> > > > > > "_default_" : {  
> > > > > > "\_source" : {  
> > > > > > "includes": ["\*"],  
> > > > > > "excludes": ["data"]  
> > > > > > }  
> > > > > > }  
> > > > > > }
> > > > > > 
> > > > > > where only data field should be hidden, but it should be searchable.
> > > > > > 
> > > > > > 1. With the template I have created the doc like {"data" : "dataone",  
> > > > > > "config": "config data", "status": "fine"}.
> > > > > > 2. When I searched for "dataone" using java api, it returned the  
> > > > > > correct data, with remaining fields displayed not displaying "data" field - _it  
> > > > > > is fine_.
> > > > > > 3. To the ssme document added some other fields like "assigned", etc
> > > > > > 
> > > > > > - They were added to document.
> > > > > > 
> > > > > > 1. But when I searched once again for "dataone" using java api, now  
> > > > > > the search is not returning the data.
> > > > > > 
> > > > > > how to make "data" field, should not be lost after updated - I guess  
> > > > > > it lost but not sure, but not returning in the search result at second  
> > > > > > time).
> > > > > > 
> > > > > > Regards,  
> > > > > > Akram.
> > > > > > 
> > > > > > On Thursday, November 21, 2013 1:58:39 PM UTC+5:30, Hannes Korte  
> > > > > > wrote:
> > > > > > 
> > > > > > > Hi Akram,
> > > > > > > 
> > > > > > > besides the solution of storing each field individually, you could  
> > > > > > > as  
> > > > > > > well include and exclude certain fields in the source:
> > > > > > > 
> > > > > > > "\_source" : {  
> > > > > > > "includes" : ["timestamp", "title", "tinyfields._"],  
> > > > > > > "excludes" : ["largefields._"]  
> > > > > > > }
> > > > > > > 
> > > > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/referenc)  
> > > > > > > e/current/mapping-source-field.html[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA)
> > > > > > > 
> > > > > > > Best regards,  
> > > > > > > Hannes
> > > > > > > 
> > > > > > > On 20.11.2013 17:39, Akram Hussain wrote:
> > > > > > > 
> > > > > > > > Hi,
> > > > > > > > 
> > > > > > > > I have some data, which should be hidden/not displayed as part of  
> > > > > > > > the  
> > > > > > > > \_source.
> > > > > > > > 
> > > > > > > > when I set \_source : { enabled : false}, source is being returned  
> > > > > > > > as null.
> > > > > > > > 
> > > > > > > > How to make some fields are not displayed, but display \_source.
> > > > > > > > 
> > > > > > > > Regards,  
> > > > > > > > Akram.
> > > > > > > 
> > > > > > > --  
> > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > Groups "elasticsearch" group.  
> > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > > 
> > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [November 22, 2013, 6:29pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/15 "2013-11-22T18:29:16Z")

</div>

Yes, I did ask before if that was a typo. 🙂

An update in Lucene is basically an atomic delete and update. Elasticsearch  
needs the source if it is to preserve the content between updates. I would  
argue that the real bug here is that elasticsearch should not have indexed  
the excluded field in the first place.

Perhaps the better question is what are you trying to solve by excluding  
the field? Maybe you can leave the source intact and solve the original  
issue in a different manner.

Cheers,

Ivan

On Fri, Nov 22, 2013 at 10:19 AM, Akram Hussain  
[akram.hussain.sk@gmail.com](mailto:akram.hussain.sk@gmail.com)wrote:

> Hi,
> 
> I was my once again copy & paste mistake.
> 
> {  
> "order\_template" : {  
> "template" : "_",  
> "order": 0,  
> "settings" :{  
> },  
> "mappings" : {  
> "default" : {  
> "\_source" : {  
> "includes": ["_"],  
> "excludes": ["_data_"]  
> }  
> }  
> }  
> }  
> }
> 
> it is the data field, which was in "excludes" list, able to search first  
> time on the "data" field, but after updating, not able to search on the  
> "data" field.
> 
> I am sorry, once again for the confusion.
> 
> Regards,  
> Akram.
> 
> On Friday, November 22, 2013 11:30:33 PM UTC+5:30, Ivan Brusic wrote:
> 
> > I do not see the issue on 0.90.5. After an update I can no longer search  
> > against the "text" field, but "data" works fine.
> > 
> > On Fri, Nov 22, 2013 at 9:55 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > 
> > > Hi,
> > > 
> > > yes, I have missed the line, the code is, as it was returned from other  
> > > method, I missed it.
> > > 
> > > SearchRequestBuilder builder = client.prepareSearch(searchCon  
> > > text.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
> > > .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());  
> > > _QueryBuilder queryBuilder =  
> > > QueryBuilders.matchPhrasePrefixQuery("data", "dataValue");_  
> > > builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuil  
> > > ders.queryFilter(queryBuilder)));
> > > 
> > > The missed line is the bold line, it will search on "data" field itself,  
> > > after updating/adding new fields to the source, the field "data" is getting  
> > > lost from source.
> > > 
> > > Let me know the possible ways to handle it.
> > > 
> > > Regards,  
> > > Akram.
> > > 
> > > On Friday, November 22, 2013 11:14:36 PM UTC+5:30, Ivan Brusic wrote:
> > > 
> > > > In your query code, you posted everything except the actual query!  
> > > > Which field are you searching against? You mention that the data field is  
> > > > lost, but you are excluding the text field. Typo?
> > > > 
> > > > I never exclude fields in source, but it seems like a field is required  
> > > > if you want to search against it. It works after indexing, but will  
> > > > disappear after updating. I doubt that is a bug, since elasticsearch has  
> > > > nothing to update. An update basically is an atomic delete/insert.
> > > > 
> > > > Cheers,
> > > > 
> > > > Ivan
> > > > 
> > > > On Thu, Nov 21, 2013 at 8:21 PM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > The following one is my template
> > > > > 
> > > > > _{_
> > > > > 
> > > > > - "order\_template" : {\*
> > > > > - "template" : "_",_
> > > > > - "order": 0,\*
> > > > > - "settings" :{\*
> > > > > - },\*
> > > > > - "mappings" : {\*
> > > > > - "_default_" : {\*
> > > > > - "\_source" : {\*
> > > > > - "includes": ["_"],_
> > > > > - "excludes": ["text"]\*
> > > > > - }\*
> > > > > - }\*
> > > > > - }\*
> > > > > - }\*  
> > > > > _}_
> > > > > 
> > > > > I am fetching the results using
> > > > > 
> > > > > _SearchRequestBuilder builder =  
> > > > > client.prepareSearch(searchContext.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)_  
> > > > > \*  
> > > > > .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());\*
> > > > > 
> > > > > _builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuilders.queryFilter(queryBuilder)));_
> > > > > 
> > > > > but updating is being done by following api
> > > > > 
> > > > > _StringBuilder scriptBuilder = new StringBuilder();_
> > > > > 
> > > > > _scriptBuilder.append("ctx.\_source.").append("assigned").append("=").append("value");_  
> > > > > _client.prepareUpdate(index, type,  
> > > > > id).setScript(scriptBuilder.toString());_
> > > > > 
> > > > > after updating with above api, the hidden field, i.e, \*data \*field is  
> > > > > lost.
> > > > > 
> > > > > I am doing any thing wrong while using api's.
> > > > > 
> > > > > Regards  
> > > > > Akram.
> > > > > 
> > > > > On Thursday, November 21, 2013 11:28:58 PM UTC+5:30, Ivan Brusic wrote:
> > > > > 
> > > > > > It would help if you provided your mapping and an example query. Are  
> > > > > > you searching against a certain field, the data field, or the \_all field?  
> > > > > > Create a gist as described here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/)[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5\_ert12o9OPxq7NdLYIOQ5Nig](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5_ert12o9OPxq7NdLYIOQ5Nig) It  
> > > > > > would help to retrieve the current mapping via the API, because some times  
> > > > > > the mapping that is in effect might not be identical to the one you  
> > > > > > supplied. 🙂
> > > > > > 
> > > > > > One issue to point out, in case it was not understood, is that some  
> > > > > > updates to the mapping will not affect documents that are currently  
> > > > > > indexed. How are you adding fields to a document? Are you reindexing or  
> > > > > > using the update API?
> > > > > > 
> > > > > > Cheers,
> > > > > > 
> > > > > > Ivan
> > > > > > 
> > > > > > On Thu, Nov 21, 2013 at 4:57 AM, Akram Hussain \<[akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)
> > > > > > 
> > > > > > > wrote:
> > > > > > 
> > > > > > > Hi,
> > > > > > > 
> > > > > > > Thanks for the reply.
> > > > > > > 
> > > > > > > It worked, but failed when try to add some other new fields to the  
> > > > > > > source from java api.
> > > > > > > 
> > > > > > > I have template like this
> > > > > > > 
> > > > > > > "mappings" : {  
> > > > > > > "_default_" : {  
> > > > > > > "\_source" : {  
> > > > > > > "includes": ["\*"],  
> > > > > > > "excludes": ["data"]  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }
> > > > > > > 
> > > > > > > where only data field should be hidden, but it should be searchable.
> > > > > > > 
> > > > > > > 1. With the template I have created the doc like {"data" :  
> > > > > > > "dataone", "config": "config data", "status": "fine"}.
> > > > > > > 2. When I searched for "dataone" using java api, it returned the  
> > > > > > > correct data, with remaining fields displayed not displaying "data" field - _it  
> > > > > > > is fine_.
> > > > > > > 3. To the ssme document added some other fields like "assigned", etc
> > > > > > > 
> > > > > > > - They were added to document.
> > > > > > > 
> > > > > > > 1. But when I searched once again for "dataone" using java api, now  
> > > > > > > the search is not returning the data.
> > > > > > > 
> > > > > > > how to make "data" field, should not be lost after updated - I guess  
> > > > > > > it lost but not sure, but not returning in the search result at second  
> > > > > > > time).
> > > > > > > 
> > > > > > > Regards,  
> > > > > > > Akram.
> > > > > > > 
> > > > > > > On Thursday, November 21, 2013 1:58:39 PM UTC+5:30, Hannes Korte  
> > > > > > > wrote:
> > > > > > > 
> > > > > > > > Hi Akram,
> > > > > > > > 
> > > > > > > > besides the solution of storing each field individually, you could  
> > > > > > > > as  
> > > > > > > > well include and exclude certain fields in the source:
> > > > > > > > 
> > > > > > > > "\_source" : {  
> > > > > > > > "includes" : ["timestamp", "title", "tinyfields._"],  
> > > > > > > > "excludes" : ["largefields._"]  
> > > > > > > > }
> > > > > > > > 
> > > > > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/referenc)  
> > > > > > > > e/current/mapping-source-field.html[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA)
> > > > > > > > 
> > > > > > > > Best regards,  
> > > > > > > > Hannes
> > > > > > > > 
> > > > > > > > On 20.11.2013 17:39, Akram Hussain wrote:
> > > > > > > > 
> > > > > > > > > Hi,
> > > > > > > > > 
> > > > > > > > > I have some data, which should be hidden/not displayed as part of  
> > > > > > > > > the  
> > > > > > > > > \_source.
> > > > > > > > > 
> > > > > > > > > when I set \_source : { enabled : false}, source is being returned  
> > > > > > > > > as null.
> > > > > > > > > 
> > > > > > > > > How to make some fields are not displayed, but display \_source.
> > > > > > > > > 
> > > > > > > > > Regards,  
> > > > > > > > > Akram.
> > > > > > > > 
> > > > > > > > --  
> > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > > > 
> > > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > > 
> > > > > > --  
> > > > > > You received this message because you are subscribed to the Google  
> > > > > > Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![akram79](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@akram79](https://discuss.elastic.co/u/akram79)\
**Post date:** [November 22, 2013, 6:35pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/16 "2013-11-22T18:35:52Z")

</div>

Hi,

As the "data" field is sensitive data, customer don't want it to be visible  
as part of the source. But it should be searchable.

Let me know, if any way to achieve this.

Regards,  
Akram.

On Friday, November 22, 2013 11:59:16 PM UTC+5:30, Ivan Brusic wrote:

> Yes, I did ask before if that was a typo. 🙂
> 
> An update in Lucene is basically an atomic delete and update.  
> Elasticsearch needs the source if it is to preserve the content between  
> updates. I would argue that the real bug here is that elasticsearch should  
> not have indexed the excluded field in the first place.
> 
> Perhaps the better question is what are you trying to solve by excluding  
> the field? Maybe you can leave the source intact and solve the original  
> issue in a different manner.
> 
> Cheers,
> 
> Ivan
> 
> On Fri, Nov 22, 2013 at 10:19 AM, Akram Hussain \<[akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > I was my once again copy & paste mistake.
> > 
> > {  
> > "order\_template" : {  
> > "template" : "_",  
> > "order": 0,  
> > "settings" :{  
> > },  
> > "mappings" : {  
> > "default" : {  
> > "\_source" : {  
> > "includes": ["_"],  
> > "excludes": ["_data_"]  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > it is the data field, which was in "excludes" list, able to search first  
> > time on the "data" field, but after updating, not able to search on the  
> > "data" field.
> > 
> > I am sorry, once again for the confusion.
> > 
> > Regards,  
> > Akram.
> > 
> > On Friday, November 22, 2013 11:30:33 PM UTC+5:30, Ivan Brusic wrote:
> > 
> > > I do not see the issue on 0.90.5. After an update I can no longer search  
> > > against the "text" field, but "data" works fine.
> > > 
> > > On Fri, Nov 22, 2013 at 9:55 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > > 
> > > > Hi,
> > > > 
> > > > yes, I have missed the line, the code is, as it was returned from other  
> > > > method, I missed it.
> > > > 
> > > > SearchRequestBuilder builder = client.prepareSearch(searchCon  
> > > > text.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
> > > > .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());  
> > > > _QueryBuilder queryBuilder =  
> > > > QueryBuilders.matchPhrasePrefixQuery("data", "dataValue");_  
> > > > builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuil  
> > > > ders.queryFilter(queryBuilder)));
> > > > 
> > > > The missed line is the bold line, it will search on "data" field  
> > > > itself, after updating/adding new fields to the source, the field "data" is  
> > > > getting lost from source.
> > > > 
> > > > Let me know the possible ways to handle it.
> > > > 
> > > > Regards,  
> > > > Akram.
> > > > 
> > > > On Friday, November 22, 2013 11:14:36 PM UTC+5:30, Ivan Brusic wrote:
> > > > 
> > > > > In your query code, you posted everything except the actual query!  
> > > > > Which field are you searching against? You mention that the data field is  
> > > > > lost, but you are excluding the text field. Typo?
> > > > > 
> > > > > I never exclude fields in source, but it seems like a field is  
> > > > > required if you want to search against it. It works after indexing, but  
> > > > > will disappear after updating. I doubt that is a bug, since elasticsearch  
> > > > > has nothing to update. An update basically is an atomic delete/insert.
> > > > > 
> > > > > Cheers,
> > > > > 
> > > > > Ivan
> > > > > 
> > > > > On Thu, Nov 21, 2013 at 8:21 PM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > The following one is my template
> > > > > > 
> > > > > > _{_
> > > > > > 
> > > > > > - "order\_template" : {\*
> > > > > > - "template" : "_",_
> > > > > > - "order": 0,\*
> > > > > > - "settings" :{\*
> > > > > > - },\*
> > > > > > - "mappings" : {\*
> > > > > > - "_default_" : {\*
> > > > > > - "\_source" : {\*
> > > > > > - "includes": ["_"],_
> > > > > > - "excludes": ["text"]\*
> > > > > > - }\*
> > > > > > - }\*
> > > > > > - }\*
> > > > > > - }\*  
> > > > > > _}_
> > > > > > 
> > > > > > I am fetching the results using
> > > > > > 
> > > > > > _SearchRequestBuilder builder =  
> > > > > > client.prepareSearch(searchContext.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)_  
> > > > > > \*  
> > > > > > .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());\*
> > > > > > 
> > > > > > _builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuilders.queryFilter(queryBuilder)));_
> > > > > > 
> > > > > > but updating is being done by following api
> > > > > > 
> > > > > > _StringBuilder scriptBuilder = new StringBuilder();_
> > > > > > 
> > > > > > _scriptBuilder.append("ctx.\_source.").append("assigned").append("=").append("value");_  
> > > > > > _client.prepareUpdate(index, type,  
> > > > > > id).setScript(scriptBuilder.toString());_
> > > > > > 
> > > > > > after updating with above api, the hidden field, i.e, \*data \*field  
> > > > > > is lost.
> > > > > > 
> > > > > > I am doing any thing wrong while using api's.
> > > > > > 
> > > > > > Regards  
> > > > > > Akram.
> > > > > > 
> > > > > > On Thursday, November 21, 2013 11:28:58 PM UTC+5:30, Ivan Brusic  
> > > > > > wrote:
> > > > > > 
> > > > > > > It would help if you provided your mapping and an example query. Are  
> > > > > > > you searching against a certain field, the data field, or the \_all field?  
> > > > > > > Create a gist as described here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/)[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNGgo5\_ert12o9OPxq7NdLYIOQ5Nig](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNGgo5_ert12o9OPxq7NdLYIOQ5Nig) It  
> > > > > > > would help to retrieve the current mapping via the API, because some times  
> > > > > > > the mapping that is in effect might not be identical to the one you  
> > > > > > > supplied. 🙂
> > > > > > > 
> > > > > > > One issue to point out, in case it was not understood, is that some  
> > > > > > > updates to the mapping will not affect documents that are currently  
> > > > > > > indexed. How are you adding fields to a document? Are you reindexing or  
> > > > > > > using the update API?
> > > > > > > 
> > > > > > > Cheers,
> > > > > > > 
> > > > > > > Ivan
> > > > > > > 
> > > > > > > On Thu, Nov 21, 2013 at 4:57 AM, Akram Hussain \<  
> > > > > > > [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\> wrote:
> > > > > > > 
> > > > > > > > Hi,
> > > > > > > > 
> > > > > > > > Thanks for the reply.
> > > > > > > > 
> > > > > > > > It worked, but failed when try to add some other new fields to the  
> > > > > > > > source from java api.
> > > > > > > > 
> > > > > > > > I have template like this
> > > > > > > > 
> > > > > > > > "mappings" : {  
> > > > > > > > "_default_" : {  
> > > > > > > > "\_source" : {  
> > > > > > > > "includes": ["\*"],  
> > > > > > > > "excludes": ["data"]  
> > > > > > > > }  
> > > > > > > > }  
> > > > > > > > }
> > > > > > > > 
> > > > > > > > where only data field should be hidden, but it should be searchable.
> > > > > > > > 
> > > > > > > > 1. With the template I have created the doc like {"data" :  
> > > > > > > > "dataone", "config": "config data", "status": "fine"}.
> > > > > > > > 2. When I searched for "dataone" using java api, it returned the  
> > > > > > > > correct data, with remaining fields displayed not displaying "data" field - _it  
> > > > > > > > is fine_.
> > > > > > > > 3. To the ssme document added some other fields like "assigned",  
> > > > > > > > etc - They were added to document.
> > > > > > > > 4. But when I searched once again for "dataone" using java api, now  
> > > > > > > > the search is not returning the data.
> > > > > > > > 
> > > > > > > > how to make "data" field, should not be lost after updated - I  
> > > > > > > > guess it lost but not sure, but not returning in the search result at  
> > > > > > > > second time).
> > > > > > > > 
> > > > > > > > Regards,  
> > > > > > > > Akram.
> > > > > > > > 
> > > > > > > > On Thursday, November 21, 2013 1:58:39 PM UTC+5:30, Hannes Korte  
> > > > > > > > wrote:
> > > > > > > > 
> > > > > > > > > Hi Akram,
> > > > > > > > > 
> > > > > > > > > besides the solution of storing each field individually, you could  
> > > > > > > > > as  
> > > > > > > > > well include and exclude certain fields in the source:
> > > > > > > > > 
> > > > > > > > > "\_source" : {  
> > > > > > > > > "includes" : ["timestamp", "title", "tinyfields._"],  
> > > > > > > > > "excludes" : ["largefields._"]  
> > > > > > > > > }
> > > > > > > > > 
> > > > > > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/referenc)  
> > > > > > > > > e/current/mapping-source-field.html[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA)
> > > > > > > > > 
> > > > > > > > > Best regards,  
> > > > > > > > > Hannes
> > > > > > > > > 
> > > > > > > > > On 20.11.2013 17:39, Akram Hussain wrote:
> > > > > > > > > 
> > > > > > > > > > Hi,
> > > > > > > > > > 
> > > > > > > > > > I have some data, which should be hidden/not displayed as part  
> > > > > > > > > > of the  
> > > > > > > > > > \_source.
> > > > > > > > > > 
> > > > > > > > > > when I set \_source : { enabled : false}, source is being  
> > > > > > > > > > returned as null.
> > > > > > > > > > 
> > > > > > > > > > How to make some fields are not displayed, but display \_source.
> > > > > > > > > > 
> > > > > > > > > > Regards,  
> > > > > > > > > > Akram.
> > > > > > > > > 
> > > > > > > > > --  
> > > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > > > > 
> > > > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > > > 
> > > > > > > --  
> > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > Groups "elasticsearch" group.  
> > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [November 22, 2013, 6:57pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/17 "2013-11-22T18:57:46Z")

</div>

Perhaps others will chime in, but off the top of my head you have two  
options:

1. Fix the data in the application side before it is returned to the actual  
client. Are you returning straight JSON back to the client? Use Jackson  
(which is what elasticsearch also uses) to transform the JSON response.

2. Use fields and not the source. Each field is indexed, but not stored by  
default. Explicitly store the fields you want and retrieve them.

However, as you demonstrated, source needs to be enabled if you want to use  
the update API. If you can skip the update API and simply reindex, the  
issue is no longer relevant. If not, post-processing the result would be  
your best bet. Maybe others would have some ideas.

Ivan

On Fri, Nov 22, 2013 at 10:35 AM, Akram Hussain  
[akram.hussain.sk@gmail.com](mailto:akram.hussain.sk@gmail.com)wrote:

> Hi,
> 
> As the "data" field is sensitive data, customer don't want it to be  
> visible as part of the source. But it should be searchable.
> 
> Let me know, if any way to achieve this.
> 
> Regards,  
> Akram.
> 
> On Friday, November 22, 2013 11:59:16 PM UTC+5:30, Ivan Brusic wrote:
> 
> > Yes, I did ask before if that was a typo. 🙂
> > 
> > An update in Lucene is basically an atomic delete and update.  
> > Elasticsearch needs the source if it is to preserve the content between  
> > updates. I would argue that the real bug here is that elasticsearch should  
> > not have indexed the excluded field in the first place.
> > 
> > Perhaps the better question is what are you trying to solve by excluding  
> > the field? Maybe you can leave the source intact and solve the original  
> > issue in a different manner.
> > 
> > Cheers,
> > 
> > Ivan
> > 
> > On Fri, Nov 22, 2013 at 10:19 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > 
> > > Hi,
> > > 
> > > I was my once again copy & paste mistake.
> > > 
> > > {  
> > > "order\_template" : {  
> > > "template" : "_",  
> > > "order": 0,  
> > > "settings" :{  
> > > },  
> > > "mappings" : {  
> > > "default" : {  
> > > "\_source" : {  
> > > "includes": ["_"],  
> > > "excludes": ["_data_"]  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > it is the data field, which was in "excludes" list, able to search first  
> > > time on the "data" field, but after updating, not able to search on the  
> > > "data" field.
> > > 
> > > I am sorry, once again for the confusion.
> > > 
> > > Regards,  
> > > Akram.
> > > 
> > > On Friday, November 22, 2013 11:30:33 PM UTC+5:30, Ivan Brusic wrote:
> > > 
> > > > I do not see the issue on 0.90.5. After an update I can no longer  
> > > > search against the "text" field, but "data" works fine.
> > > > 
> > > > On Fri, Nov 22, 2013 at 9:55 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > yes, I have missed the line, the code is, as it was returned from  
> > > > > other method, I missed it.
> > > > > 
> > > > > SearchRequestBuilder builder = client.prepareSearch(searchCon  
> > > > > text.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
> > > > > .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());  
> > > > > _QueryBuilder queryBuilder =  
> > > > > QueryBuilders.matchPhrasePrefixQuery("data", "dataValue");_  
> > > > > builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuil  
> > > > > ders.queryFilter(queryBuilder)));
> > > > > 
> > > > > The missed line is the bold line, it will search on "data" field  
> > > > > itself, after updating/adding new fields to the source, the field "data" is  
> > > > > getting lost from source.
> > > > > 
> > > > > Let me know the possible ways to handle it.
> > > > > 
> > > > > Regards,  
> > > > > Akram.
> > > > > 
> > > > > On Friday, November 22, 2013 11:14:36 PM UTC+5:30, Ivan Brusic wrote:
> > > > > 
> > > > > > In your query code, you posted everything except the actual query!  
> > > > > > Which field are you searching against? You mention that the data field is  
> > > > > > lost, but you are excluding the text field. Typo?
> > > > > > 
> > > > > > I never exclude fields in source, but it seems like a field is  
> > > > > > required if you want to search against it. It works after indexing, but  
> > > > > > will disappear after updating. I doubt that is a bug, since elasticsearch  
> > > > > > has nothing to update. An update basically is an atomic delete/insert.
> > > > > > 
> > > > > > Cheers,
> > > > > > 
> > > > > > Ivan
> > > > > > 
> > > > > > On Thu, Nov 21, 2013 at 8:21 PM, Akram Hussain \<[akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)
> > > > > > 
> > > > > > > wrote:
> > > > > > 
> > > > > > > Hi,
> > > > > > > 
> > > > > > > The following one is my template
> > > > > > > 
> > > > > > > _{_
> > > > > > > 
> > > > > > > - "order\_template" : {\*
> > > > > > > - "template" : "_",_
> > > > > > > - "order": 0,\*
> > > > > > > - "settings" :{\*
> > > > > > > - },\*
> > > > > > > - "mappings" : {\*
> > > > > > > - "_default_" : {\*
> > > > > > > - "\_source" : {\*
> > > > > > > - "includes": ["_"],_
> > > > > > > - "excludes": ["text"]\*
> > > > > > > - }\*
> > > > > > > - }\*
> > > > > > > - }\*
> > > > > > > - }\*  
> > > > > > > _}_
> > > > > > > 
> > > > > > > I am fetching the results using
> > > > > > > 
> > > > > > > _SearchRequestBuilder builder =  
> > > > > > > client.prepareSearch(searchContext.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)_  
> > > > > > > \*  
> > > > > > > .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());\*
> > > > > > > 
> > > > > > > _builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuilders.queryFilter(queryBuilder)));_
> > > > > > > 
> > > > > > > but updating is being done by following api
> > > > > > > 
> > > > > > > _StringBuilder scriptBuilder = new StringBuilder();_
> > > > > > > 
> > > > > > > _scriptBuilder.append("ctx.\_source.").append("assigned").append("=").append("value");_  
> > > > > > > _client.prepareUpdate(index, type,  
> > > > > > > id).setScript(scriptBuilder.toString());_
> > > > > > > 
> > > > > > > after updating with above api, the hidden field, i.e, \*data \*field  
> > > > > > > is lost.
> > > > > > > 
> > > > > > > I am doing any thing wrong while using api's.
> > > > > > > 
> > > > > > > Regards  
> > > > > > > Akram.
> > > > > > > 
> > > > > > > On Thursday, November 21, 2013 11:28:58 PM UTC+5:30, Ivan Brusic  
> > > > > > > wrote:
> > > > > > > 
> > > > > > > > It would help if you provided your mapping and an example query.  
> > > > > > > > Are you searching against a certain field, the data field, or the \_all  
> > > > > > > > field? Create a gist as described here: [http://www.elasticsearch](http://www.elasticsearch)  
> > > > > > > > .org/help/[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5\_ert12o9OPxq7NdLYIOQ5Nig](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5_ert12o9OPxq7NdLYIOQ5Nig) It  
> > > > > > > > would help to retrieve the current mapping via the API, because some times  
> > > > > > > > the mapping that is in effect might not be identical to the one you  
> > > > > > > > supplied. 🙂
> > > > > > > > 
> > > > > > > > One issue to point out, in case it was not understood, is that some  
> > > > > > > > updates to the mapping will not affect documents that are currently  
> > > > > > > > indexed. How are you adding fields to a document? Are you reindexing or  
> > > > > > > > using the update API?
> > > > > > > > 
> > > > > > > > Cheers,
> > > > > > > > 
> > > > > > > > Ivan
> > > > > > > > 
> > > > > > > > On Thu, Nov 21, 2013 at 4:57 AM, Akram Hussain \<  
> > > > > > > > [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\> wrote:
> > > > > > > > 
> > > > > > > > > Hi,
> > > > > > > > > 
> > > > > > > > > Thanks for the reply.
> > > > > > > > > 
> > > > > > > > > It worked, but failed when try to add some other new fields to the  
> > > > > > > > > source from java api.
> > > > > > > > > 
> > > > > > > > > I have template like this
> > > > > > > > > 
> > > > > > > > > "mappings" : {  
> > > > > > > > > "_default_" : {  
> > > > > > > > > "\_source" : {  
> > > > > > > > > "includes": ["\*"],  
> > > > > > > > > "excludes": ["data"]  
> > > > > > > > > }  
> > > > > > > > > }  
> > > > > > > > > }
> > > > > > > > > 
> > > > > > > > > where only data field should be hidden, but it should be  
> > > > > > > > > searchable.
> > > > > > > > > 
> > > > > > > > > 1. With the template I have created the doc like {"data" :  
> > > > > > > > > "dataone", "config": "config data", "status": "fine"}.
> > > > > > > > > 2. When I searched for "dataone" using java api, it returned the  
> > > > > > > > > correct data, with remaining fields displayed not displaying "data" field - _it  
> > > > > > > > > is fine_.
> > > > > > > > > 3. To the ssme document added some other fields like "assigned",  
> > > > > > > > > etc - They were added to document.
> > > > > > > > > 4. But when I searched once again for "dataone" using java api,  
> > > > > > > > > now the search is not returning the data.
> > > > > > > > > 
> > > > > > > > > how to make "data" field, should not be lost after updated - I  
> > > > > > > > > guess it lost but not sure, but not returning in the search result at  
> > > > > > > > > second time).
> > > > > > > > > 
> > > > > > > > > Regards,  
> > > > > > > > > Akram.
> > > > > > > > > 
> > > > > > > > > On Thursday, November 21, 2013 1:58:39 PM UTC+5:30, Hannes Korte  
> > > > > > > > > wrote:
> > > > > > > > > 
> > > > > > > > > > Hi Akram,
> > > > > > > > > > 
> > > > > > > > > > besides the solution of storing each field individually, you  
> > > > > > > > > > could as  
> > > > > > > > > > well include and exclude certain fields in the source:
> > > > > > > > > > 
> > > > > > > > > > "\_source" : {  
> > > > > > > > > > "includes" : ["timestamp", "title", "tinyfields._"],  
> > > > > > > > > > "excludes" : ["largefields._"]  
> > > > > > > > > > }
> > > > > > > > > > 
> > > > > > > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/referenc)  
> > > > > > > > > > e/current/mapping-source-field.html[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA)
> > > > > > > > > > 
> > > > > > > > > > Best regards,  
> > > > > > > > > > Hannes
> > > > > > > > > > 
> > > > > > > > > > On 20.11.2013 17:39, Akram Hussain wrote:
> > > > > > > > > > 
> > > > > > > > > > > Hi,
> > > > > > > > > > > 
> > > > > > > > > > > I have some data, which should be hidden/not displayed as part  
> > > > > > > > > > > of the  
> > > > > > > > > > > \_source.
> > > > > > > > > > > 
> > > > > > > > > > > when I set \_source : { enabled : false}, source is being  
> > > > > > > > > > > returned as null.
> > > > > > > > > > > 
> > > > > > > > > > > How to make some fields are not displayed, but display \_source.
> > > > > > > > > > > 
> > > > > > > > > > > Regards,  
> > > > > > > > > > > Akram.
> > > > > > > > > > 
> > > > > > > > > > --  
> > > > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > > > > > 
> > > > > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > > > > 
> > > > > > > > --  
> > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > > 
> > > > > > --  
> > > > > > You received this message because you are subscribed to the Google  
> > > > > > Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![akram79](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@akram79](https://discuss.elastic.co/u/akram79)\
**Post date:** [November 23, 2013, 2:50pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/18 "2013-11-23T14:50:12Z")

</div>

Hi,

Can you provide me the reference api's how to achieve the mentioned ways.

Regards,  
Akram.

On Saturday, November 23, 2013 12:27:46 AM UTC+5:30, Ivan Brusic wrote:

> Perhaps others will chime in, but off the top of my head you have two  
> options:
> 
> 1. Fix the data in the application side before it is returned to the  
> actual client. Are you returning straight JSON back to the client? Use  
> Jackson (which is what elasticsearch also uses) to transform the JSON  
> response.
> 
> 2. Use fields and not the source. Each field is indexed, but not stored by  
> default. Explicitly store the fields you want and retrieve them.
> 
> However, as you demonstrated, source needs to be enabled if you want to  
> use the update API. If you can skip the update API and simply reindex, the  
> issue is no longer relevant. If not, post-processing the result would be  
> your best bet. Maybe others would have some ideas.
> 
> Ivan
> 
> On Fri, Nov 22, 2013 at 10:35 AM, Akram Hussain \<[akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > As the "data" field is sensitive data, customer don't want it to be  
> > visible as part of the source. But it should be searchable.
> > 
> > Let me know, if any way to achieve this.
> > 
> > Regards,  
> > Akram.
> > 
> > On Friday, November 22, 2013 11:59:16 PM UTC+5:30, Ivan Brusic wrote:
> > 
> > > Yes, I did ask before if that was a typo. 🙂
> > > 
> > > An update in Lucene is basically an atomic delete and update.  
> > > Elasticsearch needs the source if it is to preserve the content between  
> > > updates. I would argue that the real bug here is that elasticsearch should  
> > > not have indexed the excluded field in the first place.
> > > 
> > > Perhaps the better question is what are you trying to solve by excluding  
> > > the field? Maybe you can leave the source intact and solve the original  
> > > issue in a different manner.
> > > 
> > > Cheers,
> > > 
> > > Ivan
> > > 
> > > On Fri, Nov 22, 2013 at 10:19 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I was my once again copy & paste mistake.
> > > > 
> > > > {  
> > > > "order\_template" : {  
> > > > "template" : "_",  
> > > > "order": 0,  
> > > > "settings" :{  
> > > > },  
> > > > "mappings" : {  
> > > > "default" : {  
> > > > "\_source" : {  
> > > > "includes": ["_"],  
> > > > "excludes": ["_data_"]  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > it is the data field, which was in "excludes" list, able to search  
> > > > first time on the "data" field, but after updating, not able to search on  
> > > > the "data" field.
> > > > 
> > > > I am sorry, once again for the confusion.
> > > > 
> > > > Regards,  
> > > > Akram.
> > > > 
> > > > On Friday, November 22, 2013 11:30:33 PM UTC+5:30, Ivan Brusic wrote:
> > > > 
> > > > > I do not see the issue on 0.90.5. After an update I can no longer  
> > > > > search against the "text" field, but "data" works fine.
> > > > > 
> > > > > On Fri, Nov 22, 2013 at 9:55 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > yes, I have missed the line, the code is, as it was returned from  
> > > > > > other method, I missed it.
> > > > > > 
> > > > > > SearchRequestBuilder builder = client.prepareSearch(searchCon  
> > > > > > text.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
> > > > > > .setFrom(searchContext.getOffset()).setSize(searchContext.ge  
> > > > > > tSize());  
> > > > > > _QueryBuilder queryBuilder =  
> > > > > > QueryBuilders.matchPhrasePrefixQuery("data", "dataValue");_  
> > > > > > builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuil  
> > > > > > ders.queryFilter(queryBuilder)));
> > > > > > 
> > > > > > The missed line is the bold line, it will search on "data" field  
> > > > > > itself, after updating/adding new fields to the source, the field "data" is  
> > > > > > getting lost from source.
> > > > > > 
> > > > > > Let me know the possible ways to handle it.
> > > > > > 
> > > > > > Regards,  
> > > > > > Akram.
> > > > > > 
> > > > > > On Friday, November 22, 2013 11:14:36 PM UTC+5:30, Ivan Brusic wrote:
> > > > > > 
> > > > > > > In your query code, you posted everything except the actual query!  
> > > > > > > Which field are you searching against? You mention that the data field is  
> > > > > > > lost, but you are excluding the text field. Typo?
> > > > > > > 
> > > > > > > I never exclude fields in source, but it seems like a field is  
> > > > > > > required if you want to search against it. It works after indexing, but  
> > > > > > > will disappear after updating. I doubt that is a bug, since elasticsearch  
> > > > > > > has nothing to update. An update basically is an atomic delete/insert.
> > > > > > > 
> > > > > > > Cheers,
> > > > > > > 
> > > > > > > Ivan
> > > > > > > 
> > > > > > > On Thu, Nov 21, 2013 at 8:21 PM, Akram Hussain \<  
> > > > > > > [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\> wrote:
> > > > > > > 
> > > > > > > > Hi,
> > > > > > > > 
> > > > > > > > The following one is my template
> > > > > > > > 
> > > > > > > > _{_
> > > > > > > > 
> > > > > > > > - "order\_template" : {\*
> > > > > > > > - "template" : "_",_
> > > > > > > > - "order": 0,\*
> > > > > > > > - "settings" :{\*
> > > > > > > > - },\*
> > > > > > > > - "mappings" : {\*
> > > > > > > > - "_default_" : {\*
> > > > > > > > - "\_source" : {\*
> > > > > > > > - "includes": ["_"],_
> > > > > > > > - "excludes": ["text"]\*
> > > > > > > > - }\*
> > > > > > > > - }\*
> > > > > > > > - }\*
> > > > > > > > - }\*  
> > > > > > > > _}_
> > > > > > > > 
> > > > > > > > I am fetching the results using
> > > > > > > > 
> > > > > > > > _SearchRequestBuilder builder =  
> > > > > > > > client.prepareSearch(searchContext.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)_  
> > > > > > > > \*  
> > > > > > > > .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());\*
> > > > > > > > 
> > > > > > > > _builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuilders.queryFilter(queryBuilder)));_
> > > > > > > > 
> > > > > > > > but updating is being done by following api
> > > > > > > > 
> > > > > > > > _StringBuilder scriptBuilder = new StringBuilder();_
> > > > > > > > 
> > > > > > > > _scriptBuilder.append("ctx.\_source.").append("assigned").append("=").append("value");_  
> > > > > > > > _client.prepareUpdate(index, type,  
> > > > > > > > id).setScript(scriptBuilder.toString());_
> > > > > > > > 
> > > > > > > > after updating with above api, the hidden field, i.e, \*data \*field  
> > > > > > > > is lost.
> > > > > > > > 
> > > > > > > > I am doing any thing wrong while using api's.
> > > > > > > > 
> > > > > > > > Regards  
> > > > > > > > Akram.
> > > > > > > > 
> > > > > > > > On Thursday, November 21, 2013 11:28:58 PM UTC+5:30, Ivan Brusic  
> > > > > > > > wrote:
> > > > > > > > 
> > > > > > > > > It would help if you provided your mapping and an example query.  
> > > > > > > > > Are you searching against a certain field, the data field, or the \_all  
> > > > > > > > > field? Create a gist as described here: [http://www.elasticsearch](http://www.elasticsearch)  
> > > > > > > > > .org/help/[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5\_ert12o9OPxq7NdLYIOQ5Nig](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5_ert12o9OPxq7NdLYIOQ5Nig) It  
> > > > > > > > > would help to retrieve the current mapping via the API, because some times  
> > > > > > > > > the mapping that is in effect might not be identical to the one you  
> > > > > > > > > supplied. 🙂
> > > > > > > > > 
> > > > > > > > > One issue to point out, in case it was not understood, is that  
> > > > > > > > > some updates to the mapping will not affect documents that are currently  
> > > > > > > > > indexed. How are you adding fields to a document? Are you reindexing or  
> > > > > > > > > using the update API?
> > > > > > > > > 
> > > > > > > > > Cheers,
> > > > > > > > > 
> > > > > > > > > Ivan
> > > > > > > > > 
> > > > > > > > > On Thu, Nov 21, 2013 at 4:57 AM, Akram Hussain \<  
> > > > > > > > > [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\> wrote:
> > > > > > > > > 
> > > > > > > > > > Hi,
> > > > > > > > > > 
> > > > > > > > > > Thanks for the reply.
> > > > > > > > > > 
> > > > > > > > > > It worked, but failed when try to add some other new fields to  
> > > > > > > > > > the source from java api.
> > > > > > > > > > 
> > > > > > > > > > I have template like this
> > > > > > > > > > 
> > > > > > > > > > "mappings" : {  
> > > > > > > > > > "_default_" : {  
> > > > > > > > > > "\_source" : {  
> > > > > > > > > > "includes": ["\*"],  
> > > > > > > > > > "excludes": ["data"]  
> > > > > > > > > > }  
> > > > > > > > > > }  
> > > > > > > > > > }
> > > > > > > > > > 
> > > > > > > > > > where only data field should be hidden, but it should be  
> > > > > > > > > > searchable.
> > > > > > > > > > 
> > > > > > > > > > 1. With the template I have created the doc like {"data" :  
> > > > > > > > > > "dataone", "config": "config data", "status": "fine"}.
> > > > > > > > > > 2. When I searched for "dataone" using java api, it returned the  
> > > > > > > > > > correct data, with remaining fields displayed not displaying "data" field - _it  
> > > > > > > > > > is fine_.
> > > > > > > > > > 3. To the ssme document added some other fields like "assigned",  
> > > > > > > > > > etc - They were added to document.
> > > > > > > > > > 4. But when I searched once again for "dataone" using java api,  
> > > > > > > > > > now the search is not returning the data.
> > > > > > > > > > 
> > > > > > > > > > how to make "data" field, should not be lost after updated - I  
> > > > > > > > > > guess it lost but not sure, but not returning in the search result at  
> > > > > > > > > > second time).
> > > > > > > > > > 
> > > > > > > > > > Regards,  
> > > > > > > > > > Akram.
> > > > > > > > > > 
> > > > > > > > > > On Thursday, November 21, 2013 1:58:39 PM UTC+5:30, Hannes Korte  
> > > > > > > > > > wrote:
> > > > > > > > > > 
> > > > > > > > > > > Hi Akram,
> > > > > > > > > > > 
> > > > > > > > > > > besides the solution of storing each field individually, you  
> > > > > > > > > > > could as  
> > > > > > > > > > > well include and exclude certain fields in the source:
> > > > > > > > > > > 
> > > > > > > > > > > "\_source" : {  
> > > > > > > > > > > "includes" : ["timestamp", "title", "tinyfields._"],  
> > > > > > > > > > > "excludes" : ["largefields._"]  
> > > > > > > > > > > }
> > > > > > > > > > > 
> > > > > > > > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/referenc)  
> > > > > > > > > > > e/current/mapping-source-field.html[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA)
> > > > > > > > > > > 
> > > > > > > > > > > Best regards,  
> > > > > > > > > > > Hannes
> > > > > > > > > > > 
> > > > > > > > > > > On 20.11.2013 17:39, Akram Hussain wrote:
> > > > > > > > > > > 
> > > > > > > > > > > > Hi,
> > > > > > > > > > > > 
> > > > > > > > > > > > I have some data, which should be hidden/not displayed as part  
> > > > > > > > > > > > of the  
> > > > > > > > > > > > \_source.
> > > > > > > > > > > > 
> > > > > > > > > > > > when I set \_source : { enabled : false}, source is being  
> > > > > > > > > > > > returned as null.
> > > > > > > > > > > > 
> > > > > > > > > > > > How to make some fields are not displayed, but display  
> > > > > > > > > > > > \_source.
> > > > > > > > > > > > 
> > > > > > > > > > > > Regards,  
> > > > > > > > > > > > Akram.
> > > > > > > > > > > 
> > > > > > > > > > > --  
> > > > > > > > > > > You received this message because you are subscribed to the  
> > > > > > > > > > > Google Groups "elasticsearch" group.  
> > > > > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > > > > > > 
> > > > > > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > > > > > 
> > > > > > > > > --  
> > > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > > > 
> > > > > > > --  
> > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > Groups "elasticsearch" group.  
> > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Hannes\_Korte](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hannes_korte/32/909_2.png) [@Hannes\_Korte](https://discuss.elastic.co/u/Hannes_Korte)\
**Post date:** [November 23, 2013, 3:29pm UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/19 "2013-11-23T15:29:56Z")

</div>

Hi Akram,

here are some links to achieve the approaches Ivan mentioned:

1. If you don't expose the raw Elasticsearch API to your customers, then  
you can remove the sensitive information from the source JSON in your  
own application logic before you publish it. You may want to use a  
library like Jackson to work with JSON data:  
[GitHub - FasterXML/jackson: Main Portal page for the Jackson project](https://github.com/FasterXML/jackson)

2. Use separate fields and not the source. This way was described in  
Ivans other posts.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

But I fear it may not help you, if you want to be able to use the update  
API without having to provide the sensitive information again. If this  
information is not stored, due to exclusion from the source field or due  
to a non-stored field, then you will have to provide it again when  
updating it. All fields of a document have to be reindexed when  
updating. If they are stored or part of the source they will be reused.  
If they are not, they will be not be part of the new document, unless  
they are provided with in the update.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

So, I think the easiest way to achieve what you want is a possible third  
solution: Simply exclude the sensitive data from the source and provide  
it again along with every update. Good luck!

Best regards,  
Hannes

On 23.11.2013 15:50, Akram Hussain wrote:

> Hi,
> 
> Can you provide me the reference api's how to achieve the mentioned ways.
> 
> Regards,  
> Akram.
> 
> On Saturday, November 23, 2013 12:27:46 AM UTC+5:30, Ivan Brusic wrote:
> 
> > Perhaps others will chime in, but off the top of my head you have two  
> > options:
> > 
> > 1. Fix the data in the application side before it is returned to the  
> > actual client. Are you returning straight JSON back to the client? Use  
> > Jackson (which is what elasticsearch also uses) to transform the JSON  
> > response.
> > 
> > 2. Use fields and not the source. Each field is indexed, but not stored by  
> > default. Explicitly store the fields you want and retrieve them.
> > 
> > However, as you demonstrated, source needs to be enabled if you want to  
> > use the update API. If you can skip the update API and simply reindex, the  
> > issue is no longer relevant. If not, post-processing the result would be  
> > your best bet. Maybe others would have some ideas.
> > 
> > Ivan
> > 
> > On Fri, Nov 22, 2013 at 10:35 AM, Akram Hussain \<[akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\<javascript:\>
> > 
> > > wrote:
> > 
> > > Hi,
> > > 
> > > As the "data" field is sensitive data, customer don't want it to be  
> > > visible as part of the source. But it should be searchable.
> > > 
> > > Let me know, if any way to achieve this.
> > > 
> > > Regards,  
> > > Akram.
> > > 
> > > On Friday, November 22, 2013 11:59:16 PM UTC+5:30, Ivan Brusic wrote:
> > > 
> > > > Yes, I did ask before if that was a typo. 🙂
> > > > 
> > > > An update in Lucene is basically an atomic delete and update.  
> > > > Elasticsearch needs the source if it is to preserve the content between  
> > > > updates. I would argue that the real bug here is that elasticsearch should  
> > > > not have indexed the excluded field in the first place.
> > > > 
> > > > Perhaps the better question is what are you trying to solve by excluding  
> > > > the field? Maybe you can leave the source intact and solve the original  
> > > > issue in a different manner.
> > > > 
> > > > Cheers,
> > > > 
> > > > Ivan
> > > > 
> > > > On Fri, Nov 22, 2013 at 10:19 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > I was my once again copy & paste mistake.
> > > > > 
> > > > > {  
> > > > > "order\_template" : {  
> > > > > "template" : "_",  
> > > > > "order": 0,  
> > > > > "settings" :{  
> > > > > },  
> > > > > "mappings" : {  
> > > > > "default" : {  
> > > > > "\_source" : {  
> > > > > "includes": ["_"],  
> > > > > "excludes": ["_data_"]  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }
> > > > > 
> > > > > it is the data field, which was in "excludes" list, able to search  
> > > > > first time on the "data" field, but after updating, not able to search on  
> > > > > the "data" field.
> > > > > 
> > > > > I am sorry, once again for the confusion.
> > > > > 
> > > > > Regards,  
> > > > > Akram.
> > > > > 
> > > > > On Friday, November 22, 2013 11:30:33 PM UTC+5:30, Ivan Brusic wrote:
> > > > > 
> > > > > > I do not see the issue on 0.90.5. After an update I can no longer  
> > > > > > search against the "text" field, but "data" works fine.
> > > > > > 
> > > > > > On Fri, Nov 22, 2013 at 9:55 AM, Akram Hussain [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)wrote:
> > > > > > 
> > > > > > > Hi,
> > > > > > > 
> > > > > > > yes, I have missed the line, the code is, as it was returned from  
> > > > > > > other method, I missed it.
> > > > > > > 
> > > > > > > SearchRequestBuilder builder = client.prepareSearch(searchCon  
> > > > > > > text.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
> > > > > > > .setFrom(searchContext.getOffset()).setSize(searchContext.ge  
> > > > > > > tSize());  
> > > > > > > _QueryBuilder queryBuilder =  
> > > > > > > QueryBuilders.matchPhrasePrefixQuery("data", "dataValue");_  
> > > > > > > builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuil  
> > > > > > > ders.queryFilter(queryBuilder)));
> > > > > > > 
> > > > > > > The missed line is the bold line, it will search on "data" field  
> > > > > > > itself, after updating/adding new fields to the source, the field "data" is  
> > > > > > > getting lost from source.
> > > > > > > 
> > > > > > > Let me know the possible ways to handle it.
> > > > > > > 
> > > > > > > Regards,  
> > > > > > > Akram.
> > > > > > > 
> > > > > > > On Friday, November 22, 2013 11:14:36 PM UTC+5:30, Ivan Brusic wrote:
> > > > > > > 
> > > > > > > > In your query code, you posted everything except the actual query!  
> > > > > > > > Which field are you searching against? You mention that the data field is  
> > > > > > > > lost, but you are excluding the text field. Typo?
> > > > > > > > 
> > > > > > > > I never exclude fields in source, but it seems like a field is  
> > > > > > > > required if you want to search against it. It works after indexing, but  
> > > > > > > > will disappear after updating. I doubt that is a bug, since elasticsearch  
> > > > > > > > has nothing to update. An update basically is an atomic delete/insert.
> > > > > > > > 
> > > > > > > > Cheers,
> > > > > > > > 
> > > > > > > > Ivan
> > > > > > > > 
> > > > > > > > On Thu, Nov 21, 2013 at 8:21 PM, Akram Hussain \<  
> > > > > > > > [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\> wrote:
> > > > > > > > 
> > > > > > > > > Hi,
> > > > > > > > > 
> > > > > > > > > The following one is my template
> > > > > > > > > 
> > > > > > > > > _{_
> > > > > > > > > 
> > > > > > > > > - "order\_template" : {\*
> > > > > > > > > - "template" : "_",_
> > > > > > > > > - "order": 0,\*
> > > > > > > > > - "settings" :{\*
> > > > > > > > > - },\*
> > > > > > > > > - "mappings" : {\*
> > > > > > > > > - "_default_" : {\*
> > > > > > > > > - "\_source" : {\*
> > > > > > > > > - "includes": ["_"],_
> > > > > > > > > - "excludes": ["text"]\*
> > > > > > > > > - }\*
> > > > > > > > > - }\*
> > > > > > > > > - }\*
> > > > > > > > > - }\*  
> > > > > > > > > _}_
> > > > > > > > > 
> > > > > > > > > I am fetching the results using
> > > > > > > > > 
> > > > > > > > > _SearchRequestBuilder builder =  
> > > > > > > > > client.prepareSearch(searchContext.getIndexName()).setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)_  
> > > > > > > > > \*  
> > > > > > > > > .setFrom(searchContext.getOffset()).setSize(searchContext.getSize());\*
> > > > > > > > > 
> > > > > > > > > _builder.setQuery(QueryBuilders.constantScoreQuery(FilterBuilders.queryFilter(queryBuilder)));_
> > > > > > > > > 
> > > > > > > > > but updating is being done by following api
> > > > > > > > > 
> > > > > > > > > _StringBuilder scriptBuilder = new StringBuilder();_
> > > > > > > > > 
> > > > > > > > > _scriptBuilder.append("ctx.\_source.").append("assigned").append("=").append("value");_  
> > > > > > > > > _client.prepareUpdate(index, type,  
> > > > > > > > > id).setScript(scriptBuilder.toString());_
> > > > > > > > > 
> > > > > > > > > after updating with above api, the hidden field, i.e, \*data \*field  
> > > > > > > > > is lost.
> > > > > > > > > 
> > > > > > > > > I am doing any thing wrong while using api's.
> > > > > > > > > 
> > > > > > > > > Regards  
> > > > > > > > > Akram.
> > > > > > > > > 
> > > > > > > > > On Thursday, November 21, 2013 11:28:58 PM UTC+5:30, Ivan Brusic  
> > > > > > > > > wrote:
> > > > > > > > > 
> > > > > > > > > > It would help if you provided your mapping and an example query.  
> > > > > > > > > > Are you searching against a certain field, the data field, or the \_all  
> > > > > > > > > > field? Create a gist as described here: [http://www.elasticsearch](http://www.elasticsearch)  
> > > > > > > > > > .org/help/[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5\_ert12o9OPxq7NdLYIOQ5Nig](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fhelp%2F&sa=D&sntz=1&usg=AFQjCNGgo5_ert12o9OPxq7NdLYIOQ5Nig) It  
> > > > > > > > > > would help to retrieve the current mapping via the API, because some times  
> > > > > > > > > > the mapping that is in effect might not be identical to the one you  
> > > > > > > > > > supplied. 🙂
> > > > > > > > > > 
> > > > > > > > > > One issue to point out, in case it was not understood, is that  
> > > > > > > > > > some updates to the mapping will not affect documents that are currently  
> > > > > > > > > > indexed. How are you adding fields to a document? Are you reindexing or  
> > > > > > > > > > using the update API?
> > > > > > > > > > 
> > > > > > > > > > Cheers,
> > > > > > > > > > 
> > > > > > > > > > Ivan
> > > > > > > > > > 
> > > > > > > > > > On Thu, Nov 21, 2013 at 4:57 AM, Akram Hussain \<  
> > > > > > > > > > [akram.hu...@gmail.com](mailto:akram.hu...@gmail.com)\> wrote:
> > > > > > > > > > 
> > > > > > > > > > > Hi,
> > > > > > > > > > > 
> > > > > > > > > > > Thanks for the reply.
> > > > > > > > > > > 
> > > > > > > > > > > It worked, but failed when try to add some other new fields to  
> > > > > > > > > > > the source from java api.
> > > > > > > > > > > 
> > > > > > > > > > > I have template like this
> > > > > > > > > > > 
> > > > > > > > > > > "mappings" : {  
> > > > > > > > > > > "_default_" : {  
> > > > > > > > > > > "\_source" : {  
> > > > > > > > > > > "includes": ["\*"],  
> > > > > > > > > > > "excludes": ["data"]  
> > > > > > > > > > > }  
> > > > > > > > > > > }  
> > > > > > > > > > > }
> > > > > > > > > > > 
> > > > > > > > > > > where only data field should be hidden, but it should be  
> > > > > > > > > > > searchable.
> > > > > > > > > > > 
> > > > > > > > > > > 1. With the template I have created the doc like {"data" :  
> > > > > > > > > > > "dataone", "config": "config data", "status": "fine"}.
> > > > > > > > > > > 2. When I searched for "dataone" using java api, it returned the  
> > > > > > > > > > > correct data, with remaining fields displayed not displaying "data" field - _it  
> > > > > > > > > > > is fine_.
> > > > > > > > > > > 3. To the ssme document added some other fields like "assigned",  
> > > > > > > > > > > etc - They were added to document.
> > > > > > > > > > > 4. But when I searched once again for "dataone" using java api,  
> > > > > > > > > > > now the search is not returning the data.
> > > > > > > > > > > 
> > > > > > > > > > > how to make "data" field, should not be lost after updated - I  
> > > > > > > > > > > guess it lost but not sure, but not returning in the search result at  
> > > > > > > > > > > second time).
> > > > > > > > > > > 
> > > > > > > > > > > Regards,  
> > > > > > > > > > > Akram.
> > > > > > > > > > > 
> > > > > > > > > > > On Thursday, November 21, 2013 1:58:39 PM UTC+5:30, Hannes Korte  
> > > > > > > > > > > wrote:
> > > > > > > > > > > 
> > > > > > > > > > > > Hi Akram,
> > > > > > > > > > > > 
> > > > > > > > > > > > besides the solution of storing each field individually, you  
> > > > > > > > > > > > could as  
> > > > > > > > > > > > well include and exclude certain fields in the source:
> > > > > > > > > > > > 
> > > > > > > > > > > > ```
> > > > > > > > > > > > "_source" : {
> > > > > > > > > > > > "includes" : ["timestamp", "title", "tinyfields.*"],
> > > > > > > > > > > > "excludes" : ["largefields.*"]
> > > > > > > > > > > > }
> > > > > > > > > > > > 
> > > > > > > > > > > > ```
> > > > > > > > > > > > 
> > > > > > > > > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/referenc)  
> > > > > > > > > > > > e/current/mapping-source-field.html[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fmapping-source-field.html&sa=D&sntz=1&usg=AFQjCNE15ilwN5QEN-j9w-sjFFzjpz0dUA)
> > > > > > > > > > > > 
> > > > > > > > > > > > Best regards,  
> > > > > > > > > > > > Hannes
> > > > > > > > > > > > 
> > > > > > > > > > > > On 20.11.2013 17:39, Akram Hussain wrote:
> > > > > > > > > > > > 
> > > > > > > > > > > > > Hi,
> > > > > > > > > > > > > 
> > > > > > > > > > > > > I have some data, which should be hidden/not displayed as part  
> > > > > > > > > > > > > of the  
> > > > > > > > > > > > > \_source.
> > > > > > > > > > > > > 
> > > > > > > > > > > > > when I set \_source : { enabled : false}, source is being  
> > > > > > > > > > > > > returned as null.
> > > > > > > > > > > > > 
> > > > > > > > > > > > > How to make some fields are not displayed, but display  
> > > > > > > > > > > > > \_source.
> > > > > > > > > > > > > 
> > > > > > > > > > > > > Regards,  
> > > > > > > > > > > > > Akram.
> > > > > > > > > > > > 
> > > > > > > > > > > > --  
> > > > > > > > > > > > You received this message because you are subscribed to the  
> > > > > > > > > > > > Google Groups "elasticsearch" group.  
> > > > > > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > > > > > > > 
> > > > > > > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > > > > > > 
> > > > > > > > > > --  
> > > > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > > > > 
> > > > > > > > --  
> > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > > 
> > > > > > --  
> > > > > > You received this message because you are subscribed to the Google  
> > > > > > Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google Groups  
> > > > "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:05am UTC](https://discuss.elastic.co/t/how-to-hide-some-fields-in--store-using-mappings/14498/20 "2017-07-06T02:05:08Z")

</div>


