{"record":{"id":"81d8165014458b3c","repo":"jaegertracing/jaeger","slug":"invalid-mapping-type-q-please-pass-one-of-q-q","errorCode":null,"errorMessage":"invalid mapping type %q: please pass one of %q, %q, %q, or %q as the mapping type","messagePattern":"invalid mapping type %q: please pass one of %q, %q, %q, or %q as the mapping type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/elasticsearch/mappings/command.go","lineNumber":43,"sourceCode":"\t\t\t\treturn fmt.Errorf(\"error generating mappings: %w\", err)\n\t\t\t}\n\t\t\tfmt.Println(result)\n\t\t\treturn nil\n\t\t},\n\t}\n\toptions.AddFlags(command)\n\n\treturn command\n}\n\n// generateMappings renders the index template for the requested mapping type and\n// backend version. It is an offline generator, so it renders through\n// esclient.RenderIndexTemplate for an explicitly-passed version rather than a\n// version resolved from a live cluster.\nfunc generateMappings(options Options) (string, error) {\n\tmappingType, err := esclient.MappingTypeFromString(options.Mapping)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"invalid mapping type %q: please pass one of %q, %q, %q, or %q as the mapping type\", options.Mapping, config.SpanIndexName, config.ServiceIndexName, config.DependencyIndexName, config.SamplingIndexName)\n\t}\n\tenableILM, err := strconv.ParseBool(options.UseILM)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tindexOpts := config.IndexOptions{\n\t\tShards:   options.Shards,\n\t\tReplicas: options.Replicas,\n\t}\n\tindices := config.Indices{\n\t\tIndexPrefix:  config.IndexPrefix(options.IndexPrefix),\n\t\tSpans:        indexOpts,\n\t\tServices:     indexOpts,\n\t\tDependencies: indexOpts,\n\t\tSampling:     indexOpts,\n\t}\n\trendered, err := esclient.RenderIndexTemplate(mappingType, indices, enableILM, options.ILMPolicyName, options.Version)\n\tif err != nil {","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/internal/storage/elasticsearch/mappings/command.go#L25-L61","documentation":"generateMappings validates the --mapping flag against the known Jaeger index kinds (spans, services, dependencies, sampling) by delegating to esclient.MappingTypeFromString. If the user-supplied mapping token does not match any of those names, the offline mapping generator cannot know which index template to render and returns this error listing the four accepted values. It is a CLI-input validation error, not a cluster failure.","triggerScenarios":"Running `jaeger-remote-storage`/`jaeger-es-mapping` command with `--mapping` set to a misspelled, uppercased, or entirely unknown value (e.g. --mapping=span, --mapping=Spans, --mapping=jaeger-span) so MappingTypeFromString fails.","commonSituations":"Typo in deployment scripts or Helm args; copying flags from older Jaeger versions where the mapping names differed; confusing index name (jaeger-span-0001) with the mapping type (spans).","solutions":["Set --mapping to one of: spans, services, dependencies, sampling (the config.SpanIndexName/ServiceIndexName/DependencyIndexName/SamplingIndexName values printed in the error).","Use --backend (elasticsearch/opensearch) plus a valid --mapping instead of guessing; check `--help` for the accepted list.","Fix quoting in scripts so the flag isn't receiving an empty or concatenated value."],"exampleFix":"// before\n./jaeger-es-index-cleaner --mapping span\n// after\n./jaeger-es-index-cleaner --mapping spans","handlingStrategy":"validation","validationCode":"valid := map[string]bool{\"spans\": true, \"services\": true, \"dependencies\": true, \"sampling\": true}\nif !valid[options.Mapping] {\n  return fmt.Errorf(\"--mapping must be one of spans, services, dependencies, sampling; got %q\", options.Mapping)\n}","typeGuard":"func isValidMappingType(m string) bool {\n  switch m {\n  case config.SpanIndexName, config.ServiceIndexName, config.DependencyIndexName, config.SamplingIndexName:\n    return true\n  }\n  return false\n}","tryCatchPattern":"if err != nil {\n  var invalidMapping *fmt.WrapError\n  if errors.As(err, &invalidMapping) {\n    fmt.Fprintf(os.Stderr, \"usage: --mapping spans|services|dependencies|sampling\\n\")\n    os.Exit(2)\n  }\n  return err\n}","preventionTips":["Validate CLI flags at startup with a whitelist before calling generateMappings.","Copy flag values from the error message's accepted list rather than memory.","Keep mapping names sourced from the config constants, not string literals, in tooling."],"tags":["cli","validation","elasticsearch"],"backgroundTag":"invalid-flag-value","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}