eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

Partner – LambdaTest – NPI EA (cat= Testing)
announcement - icon

Distributed systems often come with complex challenges such as service-to-service communication, state management, asynchronous messaging, security, and more.

Dapr (Distributed Application Runtime) provides a set of APIs and building blocks to address these challenges, abstracting away infrastructure so we can focus on business logic.

In this tutorial, we'll focus on Dapr's pub/sub API for message brokering. Using its Spring Boot integration, we'll simplify the creation of a loosely coupled, portable, and easily testable pub/sub messaging system:

>> Flexible Pub/Sub Messaging With Spring Boot and Dapr

1. Overview

When working with Elasticsearch, we might encounter cases when we need to modify data and metadata. One such case is renaming an existing field within an index mapping. For instance, we may want to consider naming conventions, structural inconsistencies, or clarity. However, Elasticsearch has no native mechanism to rename fields directly. In practice, renaming a field requires creating a new index, and reindexing existing data while applying a transformation script.

In this tutorial, we delve into field renaming in Elasticsearch. First, we understand why renaming a field isn’t supported directly and what workarounds exist. After that, we diagnose field structure issues to ensure a smooth renaming process. Next, we explore how to perform a safe reindex-based rename. Lastly, we also discuss best practices to minimize downtime and maintain data integrity when renaming is required.

2. Field Renaming Support

Renaming a field may look simple in theory, but Elasticsearch is designed in a way that makes such direct renames impossible. There are several reasons for this. Let’s explore each of them one by one.

2.1. Immutable Lucene Segments

Elasticsearch stores indexed documents inside immutable Lucene segments. Since they go directly into the segments, field names persist if we don’t rewrite documents. In other words, mapping updates alone are unable to adjust stored field identifiers.

Understanding this idea is critical, as it shifts the concept from renaming to deleting and recreating.

2.2. Descriptive Non-Transformative Mappings

Mapping definitions describe several properties of fields:

  • indexing
  • analysis
  • storage

However, a mapping doesn’t alter existing documents. Even if we update a mapping to include a field named new_field instead of old_field, all previously indexed documents continue to contain old_field until reindexed. Because of this, we need one more step for a rename to be actual.

2.3. No Data Rewrites on Mapping Updates

Elasticsearch accepts mapping updates for new fields even if older documents don’t contain them. This means an update that declares a new field doesn’t validate or alter existing data in any way. Consequently, an attempt to change the name of a field by adding a new mapping property results only in having two fields across newer and older documents. Furthermore, the latter can lead to long-term inconsistencies.

3. Diagnose Field-Structure Issues

Before performing a rename operation, it’s essential to understand the current state of the index. This way, we can prevent accidental data loss, incorrect mapping changes, or reindexing processes that produce inconsistent results.

3.1. Inspecting the Index Mapping

To begin with, we can inspect the mapping of an index like x_index using the _mapping API to see all fields and their types:

GET x_index/_mapping

This way, we can notice discrepancies and plan the field rename operation. Also, we can highlight whether multiple similar fields exist due to previous ingestion issues or corruption.

3.2. Checking Stored Documents

Critically, mappings may not reflect the fields present in documents, especially when dynamic mapping is enabled.

In this case, inspecting real documents might confirm which field name is currently in use:

GET x_index/_search
{
  "_source": true,
  "query": { "match_all": {} },
  "size": 5
}

If documents contain old_field but the mapping contains new_field, we know that ingestion logic hasn’t yet been updated or reindexed.

3.3. Reviewing Ingest Pipelines and Client Logic

Ingestion pipelines, log processors, serializers, and application code can all influence the structure of indexed documents. Specifically, pipelines may introduce fields dynamically or continue writing to outdated field names even after mapping updates. Verifying the ingestion path ensures that reindexing changes remain consistent once applied.

4. Field Renaming via Reindexing

To summarize, since Elasticsearch can’t rename a field in place, the correct solution is to create a new index with the updated mapping and reindex the existing data into it with a transformation script. This approach ensures consistency, maintains integrity, and adheres to the philosophy and design of Elasticsearch.

4.1. Create New Index With the Updated Mapping

First, we create a new index with the desired field name. Notably, this also includes any settings or analyzers:

PUT x_index_v2
{
  "mappings": {
    "properties": {
      "new_field": { "type": "text" }
    }
  }
}

Ensuring the correct mapping is essential. Otherwise, the new index may behave differently from the original, leading to fundamental data inconsistency.

4.2. Reindex Data with a Rename Script

The _reindex API transforms documents during the copy operation from the old index into the new one. In particular, a script can transfer the value from old_field to new_field, removing the obsolete field:

POST _reindex
{
  "source": { "index": "x_index" },
  "dest":   { "index": "x_index_v2" },
  "script": {
    "source": """
      if (ctx._source.containsKey('old_field')) {
        ctx._source.new_field = ctx._source.remove('old_field');
      }
    """
  }
}

As discussed, the renaming comes down to deletion and recreation. This guarantees that all documents in the new index consistently use the new field name.

4.3. Using Aliases for Zero-Downtime Switching

Index aliases help ensure seamless migrations. Once reindexing completes, switching the alias from the old index to the new one makes the updated structure immediately available:

POST _aliases
{
  "actions": [
    { "remove": { "index": "x_index", "alias": "current" }},
    { "add":    { "index": "x_index_v2", "alias": "current" }}
  ]
}

Thus, we avoid reconfiguring clients and enable rollback by simply switching aliases back if needed. This mechanism avoids downtime and ensures a seamless process.

5. Best Practices

There are a number of steps and precautions to take when aiming to rename fields:

  • ensuring that analyzers, filters, and field settings match expectations prevents unexpected problems
  • reindexing is operationally intensive, so running the process in a staging environment is recommended to prevent accidental data corruption
  • reindexing can place a heavy load on the cluster resources, so a maintenance window or throttle might be a good choice
  • ingestion pipelines and clients should be updated to write to new_field before reindexing begins
  • aliases enable efficient indexing and no downtime during transitions between index generations, in addition to simplifying rollback

Failing to follow these suggestions may lead to a system that’s hard to maintain, unstable, or even one that contains inconsistencies and corruption.

6. Summary

In this article, we understood how renaming fields in Elasticsearch usually means recreating and reindexing.

Essentially, rather than relying on mapping updates, the proper method involves creating a new index, defining the updated mapping, and reindexing data through a transformation script.

In conclusion, by validating mappings, reviewing ingestion behavior, using aliases, and controlling reindex operations carefully, field renaming becomes a safe and predictable procedure in any Elasticsearch environment.

Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – LS – NPI (cat=Java)
announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

eBook Jackson – NPI EA – 3 (cat = Jackson)
guest
0 Comments
Oldest
Newest
Inline Feedbacks
View all comments