Different ways to model your data in Elasticsearch

Joey Yi Zhao
9 min readJul 25, 2022

Elasticsearch is a very popular search engine and is used by many application to search customer data or any kind of analytics. The power of Elasticsearch includes full text searching, aggregation, analyser, fields mapping etc. To make good use of these features is not an easy task especially for beginners. I have experienced many projects to migrate data from relational database to Elasticsearch for different requirements. It becomes quite complex when you want to model the real world data into Elasticsearch. Some of the projects use SQL way to model the data which doesn’t make good use of the search engine. Also many engineers design the index in the way that requires many logic in application side. I agree using NOSQL data source usually requires some application side support like join, filtering, aggregating but if you don’t design it right, it will become hard to scale and leave a bad performance.

In this article, I’d like to discuss some practices on modeling data in Elasticsearch with different solutions.

In general, there are 4 ways to model your data in an index to support different relationship.

  • Application side joins: many-to-many relationships
  • Data denormalisation: many-to-many relationships
  • Parent-children: one to many relationships

--

--