# How to map 2 level object field in elastic search?

**URL:** <https://discuss.elastic.co/t/how-to-map-2-level-object-field-in-elastic-search/182501>\
**Category:** Elasticsearch\
**Created:** [May 23, 2019, 6:17pm UTC](https://discuss.elastic.co/t/how-to-map-2-level-object-field-in-elastic-search/182501 "2019-05-23T18:17:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahulkothanath](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahulkothanath/32/99122_2.png) [@rahulkothanath](https://discuss.elastic.co/u/rahulkothanath)\
**Post date:** [May 23, 2019, 6:17pm UTC](https://discuss.elastic.co/t/how-to-map-2-level-object-field-in-elastic-search/182501/1 "2019-05-23T18:17:38Z")

</div>

I have to index the below document in elastic search and need suggestion for the mapping template.

```
{
	"system": {
		"filler2": "",
		"INIT_LOOKUP_TM": "2019-05-21T14:34:49.648Z"
	},
	"pmx": {
		"coeKey": {
			"a": "ISG",
			"b": null,
			"c": "20180720164659068000",
			"d": "8A78D08FDB3127BB05F408",
			"e": "6PK3SMOgTPi6Y0mPBTNMBA=="
		},
		"Response": {
			
			"f": " way",
			"g": "60",
			"h": "fa65b61a342dfc511c42"
		},
		"content": {
			"device": "20180720160",
			"system": "5",
			"page": "MOBILESIGNIN",
			"SessionId": ""
		}
	}
}

```

the object named "system" will always havve the 2 fields in it and it is fixed.  
the "pmx" object field can vary and it can be null aslo on some documents. I need to access fields like a,b etc in future and need to make aggregations.

```
{
    "order": 0,
    "index_patterns": [
      "*system_model*"
    ],
    "settings": {
      "index": {
        "number_of_shards": "6",
        "number_of_replicas": "1"
      }
    },
    "mappings": {
      "_doc": {
        "dynamic_templates": [
          {
            "string_fields": {
              "match": "*",
              "match_mapping_type": "string",
              "mapping": {
                "type": "keyword"
              }
            }
          },
          {
            
            "tmx_datefields": {
              "path_match": "pmx.Response.*",
			  
              "match_mapping_type": "date",
              "mapping": {
                "type": "keyword"
              }
            }
            
          }
		  
        ],
        "properties": {
          "system": {
 					"properties": {

 						

 					}
 				},
				"pmx": {
            
						"type": "object"
						}
		  
        }
      }
    },
    "aliases": {
	"pmx_system":{}
	
	}
  }

```

what could be the best mapping type for the field pmx. should I define inner objects seperately or should I try nested object mapping?

thanks for reading and helping.

---

<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:** [June 20, 2019, 6:17pm UTC](https://discuss.elastic.co/t/how-to-map-2-level-object-field-in-elastic-search/182501/2 "2019-06-20T18:17:45Z")

</div>

Closed on June 20, 2019, 6:17pm UTC

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