Skip to content

Mapping attribute in class DynamicTemplate does not work as expected #7234

@matthewyang0807

Description

@matthewyang0807

Elastic.Clients.Elasticsearch version: 8.0.5

Elasticsearch version: 8.0

.NET runtime version: 6.0

Operating system version: Win11

Description of the problem including expected versus actual behavior:
A clear and concise description of what the bug is.

Steps to reproduce:

  1.  public static Union<IDictionary<string, DynamicTemplate>?, ICollection<IDictionary<string, DynamicTemplate>>?> 
      GetDynamicTemplates()
    {
        IDictionary<string, DynamicTemplate> templatesDic1 = new Dictionary<string, DynamicTemplate>();
        ICollection<IDictionary<string, DynamicTemplate>> templatesDicList = new List<IDictionary<string, DynamicTemplate>>();
    
        var template1 = new DynamicTemplate
        {
            PathMatch = "testPathMatch",
            Mapping = new Properties
            {
                **//The problem is here, I have tried many different types of property to add here, but will always lead the dynamic 
               //template creation failed**
                { "testType", new KeywordProperty() }
            }
        };
    
        templatesDic1.Add("testTemplateName", template1);
        templatesDicList.Add(templatesDic1);
        return new Union<IDictionary<string, DynamicTemplate>?, ICollection<IDictionary<string, DynamicTemplate>>?> 
         (templatesDicList);
    }
    
  2.   CreateIndexRequest cr = new CreateIndexRequest("matthew-es8-typeahead1");
       cr.Mappings.DynamicTemplates = GetDynamicTemplates();
       var indexCreateResponse = es8client.Indices.CreateAsync(cr);
       Console.WriteLine(indexCreateResponse.Result.Acknowledged);
       Console.WriteLine(indexCreateResponse.Result.ApiCallDetails.HttpStatusCode);
       Console.WriteLine(indexCreateResponse.Result.ApiCallDetails.OriginalException);
    
  3.  It will report the error 
    

image

I tried many times there is no property can be put here to make dynamic template created succsesfully.
I notice that old version in NEST6 the Mapping property type is IProperty not Properties, so can you provide me a correct way to generate the DynamicTemple?

Expected behavior
A clear and concise description of what you expected to happen.

I want to see my index "matthew-es8-typeahead1" with correct dynamic template in mapping part
"dynamic_templates": [
"testTemplateName": {
"path_match": "testPathMatch",
"mapping": {
"type": "keyword"}
}]

Provide DebugInformation (if relevant):
Elastic.Transport.TransportException: Request failed to execute. Call: Status code 400 from: PUT /matthew-es8-typeahead1. ServerError: Type: mapper_parsing_exception Reason: "Failed to parse mapping: dynamic template [testTemplateName] has invalid content [{"path_match":"testPathMatch","mapping":{"testType":{"type":"keyword"}}}], attempted to validate it with the following match_mapping_type: [object, string, long, double, boolean, date, binary]" CausedBy: "Type: illegal_argument_exception Reason: "dynamic template [testTemplateName] has invalid content [{"path_match":"testPathMatch","mapping":{"testType":{"type":"keyword"}}}], attempted to validate it with the following match_mapping_type: [object, string, long, double, boolean, date, binary]" CausedBy: "Type: mapper_parsing_exception Reason: "unknown parameter [testType] on mapper [__dynamic__testTemplateName] of type [null]"""
400

Metadata

Metadata

Assignees

No one assigned

    Labels

    8.xRelates to a 8.x client version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions