# Using Dynamic Templates

**URL:** <https://discuss.elastic.co/t/using-dynamic-templates/178887>\
**Category:** Elasticsearch\
**Created:** [April 29, 2019, 9:42am UTC](https://discuss.elastic.co/t/using-dynamic-templates/178887 "2019-04-29T09:42:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterPain](https://avatars.discourse-cdn.com/v4/letter/p/c37758/32.png) [@PeterPain](https://discuss.elastic.co/u/PeterPain)\
**Post date:** [April 29, 2019, 9:42am UTC](https://discuss.elastic.co/t/using-dynamic-templates/178887/1 "2019-04-29T09:42:15Z")

</div>

Hey there, i am a beginner and want to use a dynamic template  
i wanted to test dynamic templates by using the example in the documentation.

> **[Dynamic templates | Elasticsearch Guide \[7.0\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/dynamic-templates.html)**

> PUT my\_index  
> {  
> "mappings": {  
> "dynamic\_templates": [  
> {  
> "longs\_as\_strings": {  
> "match\_mapping\_type": "string",  
> "match": "long\__",  
> "unmatch": "_\_text",  
> "mapping": {  
> "type": "long"  
> }  
> }  
> }  
> ]  
> }  
> }

> PUT my\_index/\_doc/1  
> {  
> "name": {  
> "first": "Alice",  
> "middle": "Mary",  
> "last": "White"  
> }  
> }

> GET my\_index/\_search  
> {  
> "query": { "match\_all": {} }  
> }

This is the result for my query:

> {  
> "took" : 1,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "skipped" : 0,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : {  
> "value" : 1,  
> "relation" : "eq"  
> },  
> "max\_score" : 1.0,  
> "hits" : [  
> {  
> "\_index" : "my\_index",  
> "\_type" : "\_doc",  
> "\_id" : "1",  
> "\_score" : 1.0,  
> "\_source" : {  
> "name" : {  
> "first" : "Alice",  
> "middle" : "Mary",  
> "last" : "White"  
> }  
> }  
> }  
> ]  
> }  
> }

My question is shouldnt there be a field "full\_name" containing the information "Alice" and "White" ??

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [April 29, 2019, 10:00am UTC](https://discuss.elastic.co/t/using-dynamic-templates/178887/2 "2019-04-29T10:00:35Z")

</div>

Anything that you configure in your mappings does not change the actual documents. It only changes how Elasticsearch will _ **treat** _ the documents. So, none of it impacts the `_source` that Elasticsearch returns.

In your example, Elasticsearch will create an inverted index for a field `full_name` and it will copy the values of `name.first` and `name.last` to that inverted index, so you can query that field, even though that field does not actually exist in your document. You can think of `full_name` as a "virtual field". For example, the following query works as a result of your dynamic template:

```auto
GET my_index/_search
{
  "query": {
    "match": {
      "full_name": "alice"
    }
  }
}

```

If you want to change your actual documents, take a look at [ingest pipelines](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html).

---

<div class="post-metadata">

**Author:** ![PeterPain](https://avatars.discourse-cdn.com/v4/letter/p/c37758/32.png) [@PeterPain](https://discuss.elastic.co/u/PeterPain)\
**Post date:** [April 29, 2019, 10:41am UTC](https://discuss.elastic.co/t/using-dynamic-templates/178887/3 "2019-04-29T10:41:47Z")

</div>

Ah okay.  
Thanks a lot for the information. Yes i want to actual change the document so i am going to  
take a look at ingest pipelines.

---

<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:** [May 27, 2019, 10:41am UTC](https://discuss.elastic.co/t/using-dynamic-templates/178887/4 "2019-05-27T10:41:55Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
