Mapping Nested datatypes based on field key value

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.

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

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