Description
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:
-
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); }
-
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);
-
It will report the error
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