# Setting up "private" field in mapping, with \_source enabled?

**URL:** <https://discuss.elastic.co/t/setting-up-private-field-in-mapping-with--source-enabled/11375>\
**Category:** Elasticsearch\
**Created:** [March 29, 2013, 10:45am UTC](https://discuss.elastic.co/t/setting-up-private-field-in-mapping-with--source-enabled/11375 "2013-03-29T10:45:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Damien\_Alexandre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/damien_alexandre/32/21566_2.png) [@Damien\_Alexandre](https://discuss.elastic.co/u/Damien_Alexandre)\
**Post date:** [March 29, 2013, 10:45am UTC](https://discuss.elastic.co/t/setting-up-private-field-in-mapping-with--source-enabled/11375/1 "2013-03-29T10:45:07Z")

</div>

Hi folks,

I'm new to mapping in ES and I have a need:

I'm indexing some Documents, those documents can have a field or two that I  
do not want in the response but I want to be able to search on them (they  
should be indexed, not stored).

What is the best way to do that?

1. What I understand is that:

- set \_source.enabled to false
- set store to true all on the "public" fields
- query using fields[\*]

1. Another solution is to query and specify the fields I want explicitly:

- query using a long list of fields[title, stuff, lot, of, stuff]

1. Yet another can be the new (kind of?) "excludes" and "includes" \_source  
options:

- set \_source.excludes to [private\_data]

I did'nt found lot of documentation about the "excludes" / "includes"  
options but they seems to be by far the best option for me,  
but what about performance? Sorting?  
What are the downside of "excludes" against a fields[] query?  
I am doing this right?

Let me know!

Thx !  
Damien

--  
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:** ![vineeth\_mohan](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@vineeth\_mohan](https://discuss.elastic.co/u/vineeth_mohan)\
**Post date:** [March 29, 2013, 10:55am UTC](https://discuss.elastic.co/t/setting-up-private-field-in-mapping-with--source-enabled/11375/2 "2013-03-29T10:55:36Z")

</div>

Disable analyzer for that field in the mapping -

> **[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.

Thanks  
Vineeth

On Fri, Mar 29, 2013 at 4:15 PM, Damien Alexandre  
[dalexandre@jolicode.com](mailto:dalexandre@jolicode.com)wrote:

> Hi folks,
> 
> I'm new to mapping in ES and I have a need:
> 
> I'm indexing some Documents, those documents can have a field or two that  
> I do not want in the response but I want to be able to search on them (they  
> should be indexed, not stored).
> 
> What is the best way to do that?
> 
> 1. What I understand is that:
> 
> - set \_source.enabled to false
> - set store to true all on the "public" fields
> - query using fields[\*]
> 
> 1. Another solution is to query and specify the fields I want explicitly:
> 
> - query using a long list of fields[title, stuff, lot, of, stuff]
> 
> 1. Yet another can be the new (kind of?) "excludes" and "includes" \_source  
> options:
> 
> - set \_source.excludes to [private\_data]
> 
> I did'nt found lot of documentation about the "excludes" / "includes"  
> options but they seems to be by far the best option for me,  
> but what about performance? Sorting?  
> What are the downside of "excludes" against a fields query?  
> I am doing this right?
> 
> Let me know!
> 
> Thx !  
> Damien
> 
> --  
> 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:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 29, 2013, 11:46am UTC](https://discuss.elastic.co/t/setting-up-private-field-in-mapping-with--source-enabled/11375/3 "2013-03-29T11:46:45Z")

</div>

Hiya

> I'm indexing some Documents, those documents can have a field or two  
> that I do not want in the response but I want to be able to search on  
> them (they should be indexed, not stored).  
> What is the best way to do that?

The answer depends on this question: do you want to be able to reindex  
your documents using Elasticsearch as the source? In other words, if  
you need to change your index (eg you need to make some incompatible  
change to your mapping), would you create the new index by pulling data  
from the old index, or would you pull your data from some external data  
source?

If an external data source, then map your \_source field to use  
'excludes'.

If you want to use Elasticsearch as the data source, then keep your  
\_source field intact, and either:

- specify the fields you want returned with the fields parameter, or
- use partial fields to strip out the parts of the source that you  
don't want returned

See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/fields/)

clint

--  
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:43am UTC](https://discuss.elastic.co/t/setting-up-private-field-in-mapping-with--source-enabled/11375/4 "2017-07-06T02:43:39Z")

</div>


