# How to manage nested objects in Elasticsearch documents

DevFeed: [How to manage nested objects in Elasticsearch documents](<https://devfeed.tech/articles/how-to-manage-nested-objects-in-elasticsearch-documents-37446.md>)

Original publisher: [Read original article](<https://iridakos.com/programming/2019/05/02/add-update-delete-elasticsearch-nested-objects>)

Author: Lazarus Lazaridis

Published: 2019-05-02T12:30:00Z

Content type: tutorial

Language: en

Sources: [Lazarus Lazaridis](<https://devfeed.tech/sources/lazarus-lazaridis.md>)

Topics: [elasticsearch](<https://devfeed.tech/topics/elasticsearch.md>), [kibana](<https://devfeed.tech/topics/kibana.md>), [API](<https://devfeed.tech/topics/api.md>)

Tags: [elasticsearch](<https://devfeed.tech/tags/elasticsearch.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [kibana](<https://devfeed.tech/tags/kibana.md>), [nested-objects](<https://devfeed.tech/tags/nested-objects.md>), [opensource](<https://devfeed.tech/tags/opensource.md>), [programming](<https://devfeed.tech/tags/programming.md>), [script](<https://devfeed.tech/tags/script.md>), [scripts](<https://devfeed.tech/tags/scripts.md>), [update](<https://devfeed.tech/tags/update.md>)

## AI overview

This tutorial explains how to manage nested objects in Elasticsearch documents using Kibana. It covers defining a nested mapping, indexing a document containing cats, and adding, removing, and updating nested objects through the Update API and scripts.

## Source excerpt

In this post we are going to manage nested objects of a document indexed with Elasticsearch. The nested type is a specialised version of the object datatype that allows arrays of objects to be indexed in a way that they can be queried independently of each other. - Nested datatype - Official Elasticsearch reference Prerequisites To follow this post you need: an up and running Elasticsearch instance I use 6.7 here an up and running Kibana instance to interact with Elasticsearch Preparation The document of our index will represent a human and its nested objects will be cats (no surprises). Create the index Open your Kibana dev console and type the following to create the index. # Create the index PUT iridakos_nested_objects { "mappings": { "human": { "properties": { "name": { "type": "text" }, "cats": { "type": "nested", "properties": { "colors": { "type": "integer" }, "name": { "type": "text" }, "breed": { "type": "text" } } } } } } } Human has: a name property of type text a cats property of type nested Each cat has: a colors property of type integer a name property of type text a breed property of type text Add a human In the Kibana console, execute the following to add a human with three cats. # Index a human POST iridakos_nested_objects/human/1 { "name": "iridakos", "cats": [ { "colors": 1, "name": "Irida", "breed": "European Shorthair" }, { "colors": 2, "name": "Phoebe", "breed": "European" }, { "colors": 3, "name": "Nino", "breed": "Aegean" } ] } Confirm the insertion with: GET iridakos_nested_objects/human/1 You should see something like this: { "_index": "iridakos_nested_objects", "_type": "human", "_id": "1", "_version": 1, "found": true, "_source": { "name": "iridakos", "cats": [ { "colors": 1, "name": "Irida", "breed": "European Shorthair" }, { "colors": 2, "name": "Phoebe", "breed": "European" }, { "colors": 3, "name": "Nino", "breed": "Aegean" } ] } } Done, moving on. Managing nested objects Add a new nested object Suppose that iridakos got a new Persian