# Dynamic Nested Objects Mapping

**URL:** <https://discuss.elastic.co/t/dynamic-nested-objects-mapping/122167>\
**Category:** Elasticsearch\
**Created:** [March 1, 2018, 11:51pm UTC](https://discuss.elastic.co/t/dynamic-nested-objects-mapping/122167 "2018-03-01T23:51:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![samdash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samdash/32/21628_2.png) [@samdash](https://discuss.elastic.co/u/samdash)\
**Post date:** [March 1, 2018, 11:51pm UTC](https://discuss.elastic.co/t/dynamic-nested-objects-mapping/122167/1 "2018-03-01T23:51:58Z")

</div>

Hi,

I need help with Dynamic deeply nested Objects mapping , below is my example, the nesting can go very deep as the level attribute indicates.

```
"sections" [
 		{
 				 "level" : "1",
 				"text" : "",
                "title" : "",
 				 "sections" : []
 				 
 		},
 		{
 				 "level" : "2",
 				"text" : "",
                "title" : "",
 				 "sections" : []
 				 
 		},
 		{
 				 "level" : "3",
 				"text" : "",
                             "title" : "",
 				 "sections" : [
 				 		{
 				 			"level" : "3.1",
 				 			 "text" : "",
		               		 "title" : "",
		                	"sections" : [
		                			{
		                				"level" : "3.1.1",
	 				 			 		"text" : "",
					               		 "title" : "",
		        						"sections":[]	        			
		                			}                
		                	]
 				 		},
 				 		{
 				 			"level" : "3.2",
 				 			 "text" : "",
		               		 "title" : "",
		                	"sections" : [
		                			{
		                				"level" : "3.2.1",
	 				 			 		"text" : "",
					               		 "title" : "",
		        						"sections":[
		        							{
		        								"level" : "3.2.1.1",
	 				 			 				"text" : "",
					               		 		"title" : "",
											}
		        							
		        						]	        			
		                			}                
		                	]
 				 		}
 				 
 				 ]
 				 
 		},
 ]
```

---

<div class="post-metadata">

**Author:** ![samdash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samdash/32/21628_2.png) [@samdash](https://discuss.elastic.co/u/samdash)\
**Post date:** [March 6, 2018, 5:46pm UTC](https://discuss.elastic.co/t/dynamic-nested-objects-mapping/122167/2 "2018-03-06T17:46:39Z")

</div>

Can anyone please help on how to do mapping for the above nested object?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 6, 2018, 7:15pm UTC](https://discuss.elastic.co/t/dynamic-nested-objects-mapping/122167/3 "2018-03-06T19:15:41Z")

</div>

Send a first document in elasticsearch.  
Elasticsearch will generate a mapping for you.

Then get this mapping and edit it to suit your needs.

---

<div class="post-metadata">

**Author:** ![samdash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samdash/32/21628_2.png) [@samdash](https://discuss.elastic.co/u/samdash)\
**Post date:** [March 6, 2018, 9:47pm UTC](https://discuss.elastic.co/t/dynamic-nested-objects-mapping/122167/4 "2018-03-06T21:47:33Z")

</div>

I have inserted the first document and was able to get the mapping. however my first document had 5 level's of nested Sections and got the same form the mapping. what if i had more/less nested level's in different document? isn't there a way to specify that this is nested and don't have to do mapping for all possible nested level's ? or for the deepest nested level.

Example below :

```
{
  "test": {
    "mappings": {
      "test": {
        "properties": {
          "content": {
            "properties": {
              "sections": {
                "properties": {
                  "level": {
                    "type": "text",
                    "fields": {
                      "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                      }
                    }
                  },
                  "sections": {
                    "properties": {
                      "level": {
                        "type": "text",
                        "fields": {
                          "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                          }
                        }
                      },
                      "sections": {
                        "properties": {
                          "level": {
                            "type": "text",
                            "fields": {
                              "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                              }
                            }
                          },
                          "sections": {
                            "properties": {
                              "level": {
                                "type": "text",
                                "fields": {
                                  "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                  }
                                }
                              },
                              "sections": {
                                "properties": {
                                  "level": {
                                    "type": "text",
                                    "fields": {
                                      "keyword": {
                                        "type": "keyword",
                                        "ignore_above": 256
                                      }
                                    }
                                  },
                                  "sections": {
                                    "properties": {
                                      "level": {
                                        "type": "text",
                                        "fields": {
                                          "keyword": {
                                            "type": "keyword",
                                            "ignore_above": 256
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 6, 2018, 10:25pm UTC](https://discuss.elastic.co/t/dynamic-nested-objects-mapping/122167/5 "2018-03-06T22:25:39Z")

</div>

Have a look at dynamic templates in doc

---

<div class="post-metadata">

**Author:** ![samdash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samdash/32/21628_2.png) [@samdash](https://discuss.elastic.co/u/samdash)\
**Post date:** [March 6, 2018, 10:36pm UTC](https://discuss.elastic.co/t/dynamic-nested-objects-mapping/122167/6 "2018-03-06T22:36:24Z")

</div>

Thanks will look into this.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 3, 2018, 10:37pm UTC](https://discuss.elastic.co/t/dynamic-nested-objects-mapping/122167/7 "2018-04-03T22:37:21Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
