Skip to content
Latchkey

Elasticsearch "mapper ... cannot be changed" (illegal_argument_exception) in CI

A field mapping type in Elasticsearch is immutable once set. Trying to change text to keyword, or long to integer, on an existing index raises illegal_argument_exception. In CI this happens when a leftover index from a previous run collides with a new mapping definition.

What this error means

A mapping update fails with "illegal_argument_exception ... mapper [field] cannot be changed from type [X] to [Y]". The index already exists from an earlier run.

elasticsearch
{"error":{"type":"illegal_argument_exception","reason":"mapper [price] cannot be changed
from type [long] to [double]"},"status":400}

Common causes

Field mapping types are immutable

Elasticsearch does not allow changing the type of an existing mapped field; you must reindex into a new mapping instead.

A leftover index from a previous CI run

Persistent state or a reused volume kept the old index and mapping, so the new mapping definition conflicts with it.

How to fix it

Start each CI run from a clean index

  1. Delete the index at the start of setup so mappings are recreated fresh.
  2. Recreate it with the intended mapping.
  3. Ensure the service container does not persist a volume across runs.
Terminal
curl -X DELETE "http://localhost:9200/products"
curl -X PUT "http://localhost:9200/products" -H 'Content-Type: application/json' -d '
{"mappings":{"properties":{"price":{"type":"double"}}}}'

Reindex into a new mapping when data must survive

If you need the data, create a new index with the corrected mapping and reindex the old one into it, then swap an alias.

How to prevent it

  • Use ephemeral, unnamed volumes so no index survives between runs.
  • Delete and recreate test indices in a setup step.
  • Treat field mapping types as fixed; plan a reindex for real type changes.

Frequently asked questions

What causes ""mapper [X] cannot be changed""?
Elasticsearch does not allow changing the type of an existing mapped field; you must reindex into a new mapping instead.
How do I fix "mapper [X] cannot be changed"?
Start each CI run from a clean index

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card