# How to specify mapping with both dynamic template and \_size enabled

**URL:** https://discuss.elastic.co/t/how-to-specify-mapping-with-both-dynamic-template-and-size-enabled/231443
**Category:** Elasticsearch
**Created:** [May 7, 2020, 3:36am UTC](https://discuss.elastic.co/t/how-to-specify-mapping-with-both-dynamic-template-and-size-enabled/231443 "2020-05-07T03:36:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![plm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/plm/32/77829_2.png) [@plm](https://discuss.elastic.co/u/plm)
#### Post date: [May 7, 2020, 3:36am UTC](https://discuss.elastic.co/t/how-to-specify-mapping-with-both-dynamic-template-and-size-enabled/231443/1 "2020-05-07T03:36:46Z")

</div>

Hi,

I am trying to create an index template that includes both dynamic templates as well as enabling the \_size field. Here is what I am passing to the High Level Rest API

```auto
 PutIndexTemplateRequest templateIndexRequest = 
                            new PutIndexTemplateRequest("MyIndex*");
templateIndexRequest.mapping(<CONTENT BELOW>, XContentType.JSON);

{ 
    "dynamic_templates": 
    [ 
        {
            "pk_variable": { 
                "match_mapping_type": "*",
                "match": "*_pkVarValue",
                "mapping": { 
                    "type": "text", 
                    "fields": { 
                        "raw": { "type": "keyword" } 
                    }
                }
            }
        }
    ],
    "_size": { "enabled" : true }
}

```

This gives me the following error:

```auto
ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [_size : {enabled=true}]]]; nested: ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=Root mapping definition has unsupported parameters: [_size : {enabled=true}]]];
	at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177)
	at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:1793)
	at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1770)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1527)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1484)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1454)
	at org.elasticsearch.client.IndicesClient.putTemplate(IndicesClient.java:1163)

```

Now if I remove:

```auto
 "_size": { "enabled" : true }

```

Everything works fine. I have tried many different syntax, but don't seem to find one that works.

Any help appreciated.

Thanks,  
Philippe

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [May 7, 2020, 5:14am UTC](https://discuss.elastic.co/t/how-to-specify-mapping-with-both-dynamic-template-and-size-enabled/231443/2 "2020-05-07T05:14:00Z")

</div>

I think the \_size field requires the [mapper size plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/current/mapper-size.html) to be installed.

---

<div class="post-metadata">

### Author: ![plm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/plm/32/77829_2.png) [@plm](https://discuss.elastic.co/u/plm)
#### Post date: [May 8, 2020, 8:20pm UTC](https://discuss.elastic.co/t/how-to-specify-mapping-with-both-dynamic-template-and-size-enabled/231443/3 "2020-05-08T20:20:09Z")

</div>

Thanks for pointing this out. This got me further and I can get the \_size field enabled however I can't get it to be stored and show up in the document. I modified my mapping to:

```auto
{ 
    "dynamic_templates": 
    [ 
        {
            "pk_variable": { 
                "match_mapping_type": "*",
                "match": "*_pkVarValue",
                "mapping": { 
                    "type": "text", 
                    "fields": { 
                        "raw": { "type": "keyword" } 
                    }
                }
            }
        }
    ],
    "_size": { "enabled" : true,
                    "store": "yes" }
}

```

but then I get the following exception:

```auto
Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]: Mapping definition for [_size] has unsupported parameters: [store : yes]]:\norg.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]: Mapping definition for [_size] has unsupported parameters: [store : yes]]\n\tat org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177)\n\tat org.elasticsearch.client.RestHighLevelClient$$Lambda$832.00000000604AE0D0.apply(Unknown Source)\n\tat org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:1793)

```

Not if I remove the "store" field everything works, but the \_size field doesn't show up in my doc. I can still sort on it though.

I followed the info from this link:

> <https://github.com/elastic/elasticsearch/issues/804>
>
> Data can be derived from the size of each document indexed. The \_size field mapping can be used to enable indexing,...

I also tried with "store": true but I got the same result.

Thanks  
Philippe

---

<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: [June 5, 2020, 8:20pm UTC](https://discuss.elastic.co/t/how-to-specify-mapping-with-both-dynamic-template-and-size-enabled/231443/4 "2020-06-05T20:20:10Z")

</div>

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