Skip to content

Put mapping results in 400 #7995

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

Closed
R0boC0p opened this issue Dec 5, 2023 · 4 comments
Closed

Put mapping results in 400 #7995

R0boC0p opened this issue Dec 5, 2023 · 4 comments

Comments

@R0boC0p
Copy link

R0boC0p commented Dec 5, 2023

Elastic.Clients.Elasticsearch version: Elastic.Clients.Elasticsearch 8.11.0

Elasticsearch version: 8.11.1

.NET runtime version: 8.0.100

Operating system version: Windows 10

Description of the problem including expected versus actual behavior:
I am trying to update a dynamic template using the elastic-search-client in version 8 and being provided with a 400 error. Setting the same dynamic-template via the create index works flawlessly.

Steps to reproduce:

 var response = await _client.Indices.PutMappingAsync<DocumentT>(index, c => c
     .DynamicTemplates(new List<IDictionary<string, DynamicTemplate>>
     {
         new Dictionary<string, DynamicTemplate>
         {
             { "my-template", new DynamicTemplate
                 {
                     MatchMappingType = "string",
                     Mapping = new TextProperty
                     {
                         Analyzer = "iq_text_base",
                         Fields = new Properties
                         {
                             {
                                 "date", new DateProperty
                                 {
                                     Format = "strict_date_time||strict_date",
                                     IgnoreMalformed = true
                                 }
                             }
                         },
                         IndexOptions = IndexOptions.Freqs,
                     }
                 }
             }
         }
     }), ct);

Expected behavior
The client should send the request in an acceptable format.

**Provide DebugInformation **:

Invalid Elasticsearch response built from a unsuccessful (400) low level call on PUT: /search-sportworld-events/_mapping?pretty=true&error_trace=true
 Exception: Request failed to execute. Call: Status code 400 from: PUT /search-sportworld-events/_mapping?pretty=true&error_trace=true. 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.""

# Audit trail of this API call:
 - [1] BadResponse: Node: https://b1-sportworld-dev-eu-central-1.es.eu-central-1.aws.cloud.es.io/ Took: 00:00:00.0682161
# OriginalException: Elastic.Transport.TransportException: Request failed to execute. Call: Status code 400 from: PUT /search-sportworld-events/_mapping?pretty=true&error_trace=true. 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.""
# Request:
{
  "dynamic_templates": {
    "my-template": {
      "mapping": {
        "analyzer": "iq_text_base",
        "fields": {
          "date": {
            "format": "strict_date_time||strict_date",
            "ignore_malformed": true,
            "type": "date"
          }
        },
        "index_options": "freqs",
        "type": "text"
      },
      "match_mapping_type": "string"
    }
  }
}
# Response:
{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "Dynamic template syntax error. An array of named objects is expected.",
        "stack_trace" : "org.elasticsearch.index.mapper.MapperParsingException: Dynamic template syntax error. An array of named objects is expected.\n\tat [email protected]/org.elasticsearch.index.mapper.RootObjectMapper.processField(RootObjectMapper.java:455)\n\tat [email protected]/org.elasticsearch.index.mapper.RootObjectMapper.parse(RootObjectMapper.java:412)\n\tat [email protected]/org.elasticsearch.index.mapper.MappingParser.parse(MappingParser.java:116)\n\tat [email protected]/org.elasticsearch.index.mapper.MappingParser.parse(MappingParser.java:83)\n\tat [email protected]/org.elasticsearch.index.mapper.MapperService.parseMapping(MapperService.java:538)\n\tat [email protected]/org.elasticsearch.cluster.metadata.MetadataMappingService$PutMappingExecutor.applyRequest(MetadataMappingService.java:150)\n\tat [email protected]/org.elasticsearch.cluster.metadata.MetadataMappingService$PutMappingExecutor.execute(MetadataMappingService.java:115)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService.innerExecuteTasks(MasterService.java:1039)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService.executeTasks(MasterService.java:1004)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService.executeAndPublishBatch(MasterService.java:232)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService$BatchingTaskQueue$Processor.lambda$run$2(MasterService.java:1626)\n\tat [email protected]/org.elasticsearch.action.ActionListener.run(ActionListener.java:368)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService$BatchingTaskQueue$Processor.run(MasterService.java:1623)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService$5.lambda$doRun$0(MasterService.java:1237)\n\tat [email protected]/org.elasticsearch.action.ActionListener.run(ActionListener.java:368)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService$5.doRun(MasterService.java:1216)\n\tat [email protected]/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:983)\n\tat [email protected]/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)\n\tat java.base/java.lang.Thread.run(Thread.java:1583)\n"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Failed to parse mapping: Dynamic template syntax error. An array of named objects is expected.",
    "caused_by" : {
      "type" : "mapper_parsing_exception",
      "reason" : "Dynamic template syntax error. An array of named objects is expected.",
      "stack_trace" : "org.elasticsearch.index.mapper.MapperParsingException: Dynamic template syntax error. An array of named objects is expected.\n\tat [email protected]/org.elasticsearch.index.mapper.RootObjectMapper.processField(RootObjectMapper.java:455)\n\tat [email protected]/org.elasticsearch.index.mapper.RootObjectMapper.parse(RootObjectMapper.java:412)\n\tat [email protected]/org.elasticsearch.index.mapper.MappingParser.parse(MappingParser.java:116)\n\tat [email protected]/org.elasticsearch.index.mapper.MappingParser.parse(MappingParser.java:83)\n\tat [email protected]/org.elasticsearch.index.mapper.MapperService.parseMapping(MapperService.java:538)\n\tat [email protected]/org.elasticsearch.cluster.metadata.MetadataMappingService$PutMappingExecutor.applyRequest(MetadataMappingService.java:150)\n\tat [email protected]/org.elasticsearch.cluster.metadata.MetadataMappingService$PutMappingExecutor.execute(MetadataMappingService.java:115)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService.innerExecuteTasks(MasterService.java:1039)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService.executeTasks(MasterService.java:1004)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService.executeAndPublishBatch(MasterService.java:232)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService$BatchingTaskQueue$Processor.lambda$run$2(MasterService.java:1626)\n\tat [email protected]/org.elasticsearch.action.ActionListener.run(ActionListener.java:368)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService$BatchingTaskQueue$Processor.run(MasterService.java:1623)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService$5.lambda$doRun$0(MasterService.java:1237)\n\tat [email protected]/org.elasticsearch.action.ActionListener.run(ActionListener.java:368)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService$5.doRun(MasterService.java:1216)\n\tat [email protected]/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:983)\n\tat [email protected]/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)\n\tat java.base/java.lang.Thread.run(Thread.java:1583)\n"
    },
    "stack_trace" : "org.elasticsearch.index.mapper.MapperParsingException: Failed to parse mapping: Dynamic template syntax error. An array of named objects is expected.\n\tat [email protected]/org.elasticsearch.index.mapper.MapperService.parseMapping(MapperService.java:540)\n\tat [email protected]/org.elasticsearch.cluster.metadata.MetadataMappingService$PutMappingExecutor.applyRequest(MetadataMappingService.java:150)\n\tat [email protected]/org.elasticsearch.cluster.metadata.MetadataMappingService$PutMappingExecutor.execute(MetadataMappingService.java:115)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService.innerExecuteTasks(MasterService.java:1039)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService.executeTasks(MasterService.java:1004)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService.executeAndPublishBatch(MasterService.java:232)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService$BatchingTaskQueue$Processor.lambda$run$2(MasterService.java:1626)\n\tat [email protected]/org.elasticsearch.action.ActionListener.run(ActionListener.java:368)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService$BatchingTaskQueue$Processor.run(MasterService.java:1623)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService$5.lambda$doRun$0(MasterService.java:1237)\n\tat [email protected]/org.elasticsearch.action.ActionListener.run(ActionListener.java:368)\n\tat [email protected]/org.elasticsearch.cluster.service.MasterService$5.doRun(MasterService.java:1216)\n\tat [email protected]/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:983)\n\tat [email protected]/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)\n\tat java.base/java.lang.Thread.run(Thread.java:1583)\nCaused by: org.elasticsearch.index.mapper.MapperParsingException: Dynamic template syntax error. An array of named objects is expected.\n\tat [email protected]/org.elasticsearch.index.mapper.RootObjectMapper.processField(RootObjectMapper.java:455)\n\tat [email protected]/org.elasticsearch.index.mapper.RootObjectMapper.parse(RootObjectMapper.java:412)\n\tat [email protected]/org.elasticsearch.index.mapper.MappingParser.parse(MappingParser.java:116)\n\tat [email protected]/org.elasticsearch.index.mapper.MappingParser.parse(MappingParser.java:83)\n\tat [email protected]/org.elasticsearch.index.mapper.MapperService.parseMapping(MapperService.java:538)\n\t... 16 more\n"
  },
  "status" : 400
}

# TCP states:
  Established: 137
  TimeWait: 30
  CloseWait: 1

# ThreadPool statistics:
  Worker: 
    Busy: 1
    Free: 32766
    Min: 16
    Max: 32767
  IOCP: 
    Busy: 0
    Free: 1000
    Min: 1
    Max: 1000


@R0boC0p R0boC0p added the 8.x Relates to a 8.x client version label Dec 5, 2023
@flobernd
Copy link
Member

Hi @R0boC0p, thanks for reporting!

This is probably a specification issue where a property is incorrectly typed as "single or many" instead of just "array".

@giannik
Copy link

giannik commented Jan 14, 2024

any update on a fix for this?

@yansklyarenko
Copy link

I've also encountered this issue. Here is the workaround.

@flobernd
Copy link
Member

Duplicate of #7968

@flobernd flobernd marked this as a duplicate of #7968 Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants