# \_source and mapped fields and performance

**URL:** <https://discuss.elastic.co/t/-source-and-mapped-fields-and-performance/4898>\
**Category:** Elasticsearch\
**Created:** [July 19, 2011, 4:52pm UTC](https://discuss.elastic.co/t/-source-and-mapped-fields-and-performance/4898 "2011-07-19T16:52:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![davrob](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@davrob](https://discuss.elastic.co/u/davrob)\
**Post date:** [July 19, 2011, 4:52pm UTC](https://discuss.elastic.co/t/-source-and-mapped-fields-and-performance/4898/1 "2011-07-19T16:52:22Z")

</div>

Hi,

As I understand it, Elastic Search will automatically store whatever  
JSON is passed into the source, no matter what fields are passed in  
the mapping (even if the type mapping is set to dynamic:false), when I  
do this?

```
    IndexRequest indexOperation = Requests.indexRequest(indexName)
    	.type(jsonBean.getIndexType())
    	.id("" + jsonBean.getId())
    	.create(false)
    	.source(jsonBean.getJson());

	bulkOperation.add(indexOperation);

```

My Mapping looks like this:

{  
"contact" : {  
"dynamic" : false,  
"properties" : {

```
        "id":{"type" : "integer", "index" : "not_analyzed"},
        "fullName" : {"type" : "string"},
		"person_name" : {"type" : "string", "index" : "not_analyzed"},
		"person_name_lc" : {"type" : "string", "index" : "not_analyzed"},
		"displayAddress" : {"type" : "string"}

```

.... etc.

Is that correct? And, as a matter of best practice, is it better just  
to leave non-searched fields out of the mapping and just let them be  
returned in the source, would this bring any performance benefits?

Best Regards,

David.

---

<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:** [July 19, 2011, 5:04pm UTC](https://discuss.elastic.co/t/-source-and-mapped-fields-and-performance/4898/2 "2011-07-19T17:04:30Z")

</div>

Hi David

> As I understand it, Elastic Search will automatically store whatever  
> JSON is passed into the source, no matter what fields are passed in  
> the mapping (even if the type mapping is set to dynamic:false), when I  
> do this?

correct

> Is that correct? And, as a matter of best practice, is it better just  
> to leave non-searched fields out of the mapping and just let them be  
> returned in the source, would this bring any performance benefits?

There is a mapping for every field that you include in the \_source.

You can control what happens to each field with (amongst other things)  
the "index" parameter:

- analyzed
- not\_analyzed (searchable, but not processed by analyzers)
- no (not searchable)

So if you don't want certain fields to be searchable at all, then just  
set them to {index: "no"},

{ title: { type: "string" }} # analyzed by default  
{ num: { type: "integer"}} # not\_analyzed by default  
{ hidden: { type: "string", index: "no"}}

clint

---

<div class="post-metadata">

**Author:** ![davrob](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@davrob](https://discuss.elastic.co/u/davrob)\
**Post date:** [July 20, 2011, 9:49am UTC](https://discuss.elastic.co/t/-source-and-mapped-fields-and-performance/4898/3 "2011-07-20T09:49:09Z")

</div>

Hi Clint,

Thanks for the reply, when you say:

```
            "There is a mapping for every field that you include

```

in the \_source. "

is that true even when the type mapping is set to dynamic false as so:

```
	{
		"contact" : {
			"dynamic" : false,
			"properties" : {

```

If so, then what is the dynamic=false property doing?

David.

On Jul 19, 6:04 pm, Clinton Gormley [clin...@iannounce.co.uk](mailto:clin...@iannounce.co.uk) wrote:

> Hi David
> 
> > As I understand it, Elastic Search will automatically store whatever  
> > JSON is passed into the source, no matter what fields are passed in  
> > the mapping (even if the type mapping is set to dynamic:false), when I  
> > do this?
> 
> correct
> 
> > Is that correct? And, as a matter of best practice, is it better just  
> > to leave non-searched fields out of the mapping and just let them be  
> > returned in the source, would this bring any performance benefits?
> 
> There is a mapping for every field that you include in the \_source.
> 
> You can control what happens to each field with (amongst other things)  
> the "index" parameter:
> 
> - analyzed
> - not\_analyzed (searchable, but not processed by analyzers)
> - no (not searchable)
> 
> So if you don't want certain fields to be searchable at all, then just  
> set them to {index: "no"},
> 
> { title: { type: "string" }} # analyzed by default  
> { num: { type: "integer"}} # not\_analyzed by default  
> { hidden: { type: "string", index: "no"}}
> 
> clint

---

<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:** [July 20, 2011, 9:52am UTC](https://discuss.elastic.co/t/-source-and-mapped-fields-and-performance/4898/4 "2011-07-20T09:52:17Z")

</div>

Hi David

> ```
> "There is a mapping for every field that you include
> 
> ```
> 
> in the \_source. "
> 
> is that true even when the type mapping is set to dynamic false as so:

No, you are correct: this is exactly what dynamic mapping is for.

And if you set it to 'strict' instead, then not only will it not add new  
fields automatically, it will also throw an error

clint

---

<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, 4:00am UTC](https://discuss.elastic.co/t/-source-and-mapped-fields-and-performance/4898/5 "2017-07-06T04:00:04Z")

</div>


