March 17, 2025
Nested Fields in Elasticsearch: Why and How to Avoid Them

Nested Fields in Elasticsearch: Why and How to Avoid Them

The Nested field type in Elasticsearch and OpenSearch is not as innocent as one would think. Let’s look at what they are used for, the challenges with them, and possible alternatives.

Elasticsearch is a document-oriented data store. Trying to use relational models like in-use in RDBMS systems like Postgresql and MySQL, with Elasticsearch is prone to failure.

Yet, Elasticsearch allows you to model complex data structures using nested fields, which are useful for preserving relationships within arrays of objects. Unlike standard object fields, nested fields store each object in an array as a separate hidden document, enabling precise querying. However, this approach comes with significant downsides.

Let’s review the common issues and challenges with nested fields, then look at solutions and alternatives given the common use-cases where they are being used.

What are Nested Fields?