-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Mapping attribute in class DynamicTemplate does not work as expected #7234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for raising this, @matthewyang0807. This is related to #7221. When we fix the generated code, I expect some changes to the types, which may resolve this as a by-product. If not, we can investigate this after a PR is merged, fixing the first issue. |
@matthewyang0807 A fixed has been merged which will ship in the next patch release. Once that's available you can achieve your objective with the code along the lines of: var myTemplate = new DynamicTemplate
{
PathMatch = "testPathMatch",
Mapping = new KeywordProperty()
};
var createIndexRequest = new CreateIndexRequest("testing")
{
Mappings = new TypeMapping
{
DynamicTemplates = new[]
{
new Dictionary<string, DynamicTemplate>
{
{ "testTemplateName", myTemplate }
}
}
}
};
var indexCreateResponse = await client.Indices.CreateAsync(createIndexRequest); |
@stevejgordon Error Below: Elastic.Transport.TransportException: Request failed to execute. Call: Status code 400 from: PUT /matthew-fix-dynamictemplate-test. ServerError: Type: mapper_parsing_exception Reason: "Failed to parse mapping: Dynamic template syntax error. An array of named objects is expected." CausedBy: "Type: mapper_parsing_exception Reason: "Dynamic template syntax error. An array of named objects is expected."" |
@matthewyang0807 The original exception was caused by a malformed request. This new error is subtly different but also due to the request format not being excepted by the server. In this case, it appears to be an issue in the ES specification, which I'll review and fix before we code-gen this request again. I'll reopen to track. |
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:
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
The text was updated successfully, but these errors were encountered: