Maintaining Nested Arrays of Objects in Elasticsearch 7.13

2 hours
  • 3 Learning Objectives

About this Hands-on Lab

Elasticsearch likes flattened and denormalized data. So when it comes to storing arrays of objects, you need to take some special precautions in order to maintain the relationships between each object. In this hands-on lab, you will get to configure indices in Elasticsearch such that the relationships of nested arrays of objects are properly maintained.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create the ecommerce_fixed Index

From the Kibana console:

  • Copy the mappings of the ecommerce index.
  • Create the ecommerce_fixed index with the copied mappings but configure the products object as nested.
  • Configure the ecommerce_fixed index with one primary and zero replica shards.
Reindex the ecommerce Index to ecommerce_fixed Index

From the Kibana console, reindex the ecommerce index to the ecommerce_fixed index.

Perform a Nested Search on the Products Object of the ecommerce_fixed Index

From the Kibana console, craft a nested search on a product object for the ecommerce_fixed index.

Additional Resources

Logging In to the Elastic Environment

  1. Open a new browser tab and navigate to the public IP address of the es1 node provided on the lab page (e.g., http://public_ip).
  2. Log in using the username elastic and password elastic_acg.

Lab Scenario

You work as a data infrastructure engineer for an online clothing store. You have identified a mapping issue with the ecommerce index that stores all the orders made by customers. Specifically, each order document has a products object that contains a nested array of objects; one for each product in the order. However, the nested array of products is not configured to maintain the relationships of each individual product.

To solve this problem you will need to create the ecommerce_fixed index with the same mappings as the ecommerce index with the exception that the products object must be configured to maintain the relationships of the nested array of objects. Also, make sure the ecommerce_fixed index has one primary and zero replica shards in order to allocate with a green state in the single-node cluster. Then, you will need to reindex the ecommerce data to the ecommerce_fixed index. Lastly, you should preform a nested query on the products object of the ecommerce_fixed index to validate the mapping. A nested query that spans products should no longer match while nested queries that do not span multiple products should match.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?