How to specify mapping with both dynamic template and _size enabled

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

 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:

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:

 "_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

I think the _size field requires the mapper size plugin to be installed.

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:

{ 
    "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:

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:

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

Thanks
Philippe

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