Dynamic Nested Objects Mapping


(Sam) #1

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" : "",
											}
		        							
		        						]	        			
		                			}                
		                	]
 				 		}
 				 
 				 ]
 				 
 		},
 ]

(Sam) #2

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


(David Pilato) #3

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

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


(Sam) #4

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
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

(David Pilato) #5

Have a look at dynamic templates in doc


(Sam) #6

Thanks will look into this.


(system) #7

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