# Mapping Nested datatypes based on field key value

**URL:** <https://discuss.elastic.co/t/mapping-nested-datatypes-based-on-field-key-value/131335>\
**Category:** Elasticsearch\
**Created:** [May 10, 2018, 5:22pm UTC](https://discuss.elastic.co/t/mapping-nested-datatypes-based-on-field-key-value/131335 "2018-05-10T17:22:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lewis\_John\_Mcgibbney](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lewis_john_mcgibbney/32/973_2.png) [@Lewis\_John\_Mcgibbney](https://discuss.elastic.co/u/Lewis_John_Mcgibbney)\
**Post date:** [May 10, 2018, 5:22pm UTC](https://discuss.elastic.co/t/mapping-nested-datatypes-based-on-field-key-value/131335/1 "2018-05-10T17:22:03Z")

</div>

Hi Folks,  
I am trying to correctly model the following documents... which differ slightly particularly within the "geometries" field.

**Document 1**

```
	{
		"id": "EONET_3497",
		"title": "Tye River Fire",
        "description": "",
		"link": "https://eonet.sci.gsfc.nasa.gov/api/v2.1/events/EONET_3497",
		"categories": [
			{
				"id": 8,
				"title": "Wildfires"
			}
		],
		"sources": [
			{
				"id": "InciWeb",
				"url": "http://inciweb.nwcg.gov/incident/5783/"
			}
		
		],
		"geometries": [
			{
				"date": "2018-05-03T18:16:00Z",
				"type": "Point", 
				"coordinates": [-79.183, 37.894]
			}
		
		]
	},

```

**Document 2**

```
	{
		"id": "EONET_3465",
		"title": "Ebro River, Spain Flood",
        "description": "",
		"link": "https://eonet.sci.gsfc.nasa.gov/api/v2.1/events/EONET_3465",
		"closed": "2018-04-19T00:00:00Z",
		"categories": [
			{
				"id": 9,
				"title": "Floods"
			}
		],
		"sources": [
			{
				"id": "CEMS",
				"url": "http://emergency.copernicus.eu/mapping/list-of-components/EMSR279"
			}
		
		],
		"geometries": [
			{
				"date": "2018-04-12T00:00:00Z",
				"type": "Polygon", 
				"coordinates": [[[-2.84912109375, 41.37201604041778], [-2.84912109375, 42.96219666198758], [-0.44921875, 42.96219666198758], [-0.44921875, 41.37201604041778], [-2.84912109375, 41.37201604041778] ]]
			}
		
		]
	},

```

Right now my mapping looks as follows

```
{
    "eonet_event": {
        "properties": {
            "sources": {
                "type": "nested",
                "fields": {
                    "id": {
                        "ignore_above": 256,
                        "type": "keyword"
                    },
                    "url": {
                        "ignore_above": 256,
                        "type": "keyword"
                    }
                }
            },
            "geometries": {
                "type": "nested",
                "fields": {
                    "date": {
                        "ignore_above": 256,
                        "type": "date"
                    },
                    "type": {
                        "ignore_above": 256,
                        "type": "keyword"
                    },
                    "coordinates": {
                        "ignore_above": 256,
                        "type": "keyword"
                    }
                }
            },
            "link": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "ignore_above": 256,
                        "type": "keyword"
                    }
                }
            },
            "closed": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "ignore_above": 256,
                        "type": "keyword"
                    }
                }
            },
            "description": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "ignore_above": 256,
                        "type": "keyword"
                    }
                }
            },
            "categories": {
                "type": "nested",
                "fields": {
                    "id": {
                        "ignore_above": 256,
                        "type": "integer"
                    },
                    "title": {
                        "ignore_above": 256,
                        "type": "keyword"
                    }
                }
            },
            "id": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "ignore_above": 256,
                        "type": "keyword"
                    }
                }
            },
            "title": {
                "type": "completion",
                "fields": {
                    "keyword": {
                        "ignore_above": 256,
                        "type": "keyword"
                    }
                }
            }
        }
    }
}

```

Depending on the value of the **geometries/type** value e.g either Point or Polygon, I am looking to assign a **geo\_point** or **geo\_shape** datatype respectively.

Can someone please guide me in the mapping implementation and whether an existing analyzer is available for nested conditional datatype assignment based upon nested field value?

Thank you in advance folks.

---

<div class="post-metadata">

**Author:** ![Lewis\_John\_Mcgibbney](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lewis_john_mcgibbney/32/973_2.png) [@Lewis\_John\_Mcgibbney](https://discuss.elastic.co/u/Lewis_John_Mcgibbney)\
**Post date:** [May 10, 2018, 5:30pm UTC](https://discuss.elastic.co/t/mapping-nested-datatypes-based-on-field-key-value/131335/2 "2018-05-10T17:30:48Z")

</div>

It looks like I need to use [https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html)

---

<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 7, 2018, 5:31pm UTC](https://discuss.elastic.co/t/mapping-nested-datatypes-based-on-field-key-value/131335/3 "2018-06-07T17:31:01Z")

</div>

Closed on June 7, 2018, 5:31pm UTC

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