8.7. Summary

Lots of use cases have to deal with relational data, and in this chapter you saw how you can deal with these:

Object mapping, mostly useful for one-to-one relationships

Nested documents and parent-child structures, which deal with one-to-many relationships

Denormalizing and application-side joins, which are mostly helpful with many-to-many relationships

Joining hurts performance, even when it’s local, so it’s typically a good idea to put as many properties as you can in a single document. Object mapping helps with this because it allows hierarchies in your documents. Searches and aggregations work here as they do with a flat-structured document; you have to refer to fields using their full path, like location.name.

When you need to avoid cross-object matches, nested and parent/child documents are available to help:

Nested documents are basically index-time joins, putting multiple Lucene documents in a single block. To the application, the block looks like a single Elasticsearch document.

The _parent field allows you to point a document to another document of another type in the same index to be its parent. Elasticsearch will use routing to make sure a parent and all its children land in the same shard so that it can perform a local join at query time.

You can search nested and parent-child documents with the following queries and filters:

nested query and filter has_child query and filter has_parent query and filter

Aggregations work across the relationship only with nested documents through the nested and reverse_nested aggregation types.

Objects, nested and parent-child documents, and the generic technique of denormalizing can be combined in any way so you can get a good mix of performance and functionality.

Part 2.

In this part, we’ll shift the focus from development to production. There are three chapters that focus on scaling Elasticsearch, tuning it for better performance, and maintaining it. You’ll also get a deeper understanding of the functionality we covered in part 1 as we explore how various features perform. This information is valuable for both development and operations, as they typically have to work together to set up Elasticsearch in a way that can scale out to the production requirements and be easy to maintain.