jaegertracing/jaeger · error

error generating mappings: %w

Error message

error generating mappings: %w

What it means

The elasticsearch-mappings cobra command (esmapping-generator) runs generateMappings and wraps any error it returns as "error generating mappings" before exiting. generateMappings validates the mapping type, parses the ILM flag, and renders the index template; any failure in those steps surfaces through this wrapper. The process prints nothing to stdout and cobra reports the wrapped error.

Source

Thrown at internal/storage/elasticsearch/mappings/command.go:25

	"fmt"
	"strconv"

	"github.com/spf13/cobra"

	"github.com/jaegertracing/jaeger/internal/storage/elasticsearch/config"
	"github.com/jaegertracing/jaeger/internal/storage/elasticsearch/esclient"
)

func Command() *cobra.Command {
	options := Options{}
	command := &cobra.Command{
		Use:   "elasticsearch-mappings",
		Short: "Jaeger esmapping-generator prints rendered mappings as string",
		Long:  "Jaeger esmapping-generator renders passed templates with provided values and prints rendered output to stdout",
		RunE: func(_ *cobra.Command, _ /* args */ []string) error {
			result, err := generateMappings(options)
			if err != nil {
				return fmt.Errorf("error generating mappings: %w", err)
			}
			fmt.Println(result)
			return nil
		},
	}
	options.AddFlags(command)

	return command
}

// generateMappings renders the index template for the requested mapping type and
// backend version. It is an offline generator, so it renders through
// esclient.RenderIndexTemplate for an explicitly-passed version rather than a
// version resolved from a live cluster.
func generateMappings(options Options) (string, error) {
	mappingType, err := esclient.MappingTypeFromString(options.Mapping)
	if err != nil {
		return "", 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)

View on GitHub (pinned to 806f444784)

Solutions

  1. Read the inner (%w) error: it says whether the mapping type, the ILM bool, or the template rendering failed.
  2. Fix --mapping to one of spans, services, dependencies, or sampling.
  3. Fix --use-ilm to a strconv.ParseBool-accepted value: true/false (or 1/0, t/f, TRUE/FALSE, etc.).
  4. If rendering fails, check --es-version and ILM policy name are supported by the installed Jaeger version; upgrade or adjust flags accordingly.

Example fix

// before
esmapping-generator --mapping span --use-ilm yes
// after
esmapping-generator --mapping spans --use-ilm true
Defensive patterns

Strategy: validation

Validate before calling

validMappings := map[string]bool{"spans": true, "services": true, "dependencies": true, "sampling": true}
if !validMappings[options.Mapping] {
	return fmt.Errorf("--mapping must be one of spans, services, dependencies, sampling")
}
if _, err := strconv.ParseBool(options.UseILM); err != nil {
	return fmt.Errorf("--use-ilm must be a boolean (true/false)")
}

Try / catch

out, err := exec.Command("esmapping-generator", "--mapping", "spans", "--use-ilm", "true").Output()
if err != nil {
	var ee *exec.ExitError
	if errors.As(err, &ee) {
		log.Fatalf("esmapping-generator failed: %s", ee.Stderr) // contains the wrapped cause
	}
	return err
}

Prevention

When it happens

Trigger: Running the esmapping-generator with an invalid --mapping type (not spans/services/dependencies/sampling), a --use-ilm flag that is not a valid bool, or a version/template combination that makes RenderIndexTemplate fail (e.g. unsupported --es-version).

Common situations: CI scripts invoking esmapping-generator with typo'd flags; upgrading Jaeger where the accepted mapping-type names changed; passing ILM options like "yes"/"1" variants strconv.ParseBool rejects (only 1/t/T/TRUE/true/True/0/f/F/FALSE/false/False accepted); an --es-version the renderer cannot handle.

Related errors


AI-assisted analysis of jaegertracing/jaeger@806f444784 (2026-09-01). Data as JSON: /api/errors/cf99e7f64ce96db6. Report an issue: GitHub.