# Dynamic Template and object type

**URL:** <https://discuss.elastic.co/t/dynamic-template-and-object-type/93968>\
**Category:** Elasticsearch\
**Created:** [July 20, 2017, 2:51pm UTC](https://discuss.elastic.co/t/dynamic-template-and-object-type/93968 "2017-07-20T14:51:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edta](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@Edta](https://discuss.elastic.co/u/Edta)\
**Post date:** [July 20, 2017, 2:51pm UTC](https://discuss.elastic.co/t/dynamic-template-and-object-type/93968/1 "2017-07-20T14:51:54Z")

</div>

Hello,

I try to create a template that store in Elasticsearch only the properties inside "Data" with a dynamic Template.  
My output come from the MetricBeat (call by Jolokia the Endpoint metrics of Spring boot application).

My output is as follow :

```auto
{
  "@timestamp": "2017-07-17T10:09:50.248Z",
  "beat": {
    "hostname": "XXXX",
    "name": "XXXX",
    "version": "5.5.0"
  },
  "jolokia": {
    "metric": {
      "data": {
        "classes": 9203.000000,
        "classes.loaded": 9203.000000,
        "classes.unloaded": 0.000000,
        "counter.status.200.jolokia.star-star": 1.000000,
        "gauge.response.jolokia.star-star": 173.000000,
        "gc.copy.count": 108.000000,
        "gc.copy.time": 344.000000,
        "gc.marksweepcompact.count": 3.000000,
        "gc.marksweepcompact.time": 122.000000,
        "heap": 253440.000000,
        "heap.committed": 48804.000000,
        "heap.init": 16384.000000,
        "heap.used": 34625.000000,
        "instance.uptime": 2826140.000000,
        "mem": 81738.000000,
        "mem.free": 14178.000000,
        "nonheap": 0.000000,
        "nonheap.committed": 34144.000000,
        "nonheap.init": 160.000000,
        "nonheap.used": 32934.000000,
        "processors": 4.000000,
        "systemload.average": -1.000000,
        "threads": 21.000000,
        "threads.daemon": 12.000000,
        "threads.peak": 21.000000,
        "threads.totalStarted": 25.000000,
        "uptime": 2836409.000000
      }
    }
  },
  "metricset": {
    "host": "localhost:XXXX",
    "module": "jolokia",
    "name": "jmx",
    "namespace": "metric",
    "rtt": 83257
  },
  "type": "metricsets"
}

```

My template is :

```auto
{
	"template": "metric-springboot-*",
	"mappings": {
		"metric_data": {
			"properties": {
				"@timestamp": {
					"type": "date"
				},
				"jolokia": {
					"properties": {
						"metric": {
							"properties": {
								"data": {
									"dynamic": "true",
									"type": "object"
								}
							}
						}
					}
				}
			},
			"dynamic_templates": [
			{	
				"data_value_mapping": {
					"path_match": "jolokia.metric.data.*",
					"mapping": {
						"type": "float",
						"index": false
					}
				}
			}
			]
		}
	}
}

```

But I have the following error :

```auto
java.lang.IllegalArgumentException: Can't merge a non object mapping [jolokia.me
tric.data.classes] with an object mapping [jolokia.metric.data.classes]

```

My metricbeat configuration is :

```auto
metricbeat.modules:
- module: jolokia
  metricsets: ["jmx"]
  enabled: true
  period: 10s
  hosts: ["localhost:8081"]
  namespace: "metric"
  path: "xxxx/jolokia/read"
  jmx.mappings:
    - mbean: 'org.springframework.boot:name=metricsEndpoint,type=Endpoint'
      attributes:
        - attr: Data
          field: data
          field_type: java.Object

output.elasticsearch:
  hosts: ["localhost:9200"]
  index: "metric-springboot-smartphone"
  template.name: "metric_springboot"
  template.path: "metricbeat.template-metrics.json"
  template.versions.2x.enabled: false
  template.versions.6x.enabled: false

```

Thank for your help

---

<div class="post-metadata">

**Author:** ![Edta](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@Edta](https://discuss.elastic.co/u/Edta)\
**Post date:** [July 21, 2017, 7:08am UTC](https://discuss.elastic.co/t/dynamic-template-and-object-type/93968/2 "2017-07-21T07:08:03Z")

</div>

No body for help me ?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [July 21, 2017, 1:48pm UTC](https://discuss.elastic.co/t/dynamic-template-and-object-type/93968/3 "2017-07-21T13:48:37Z")

</div>

> [@Edta](#):
>
> "classes": 9203.000000,  
> "classes.loaded": 9203.000000

This is the problem, the first line makes `classes` a `float` but the second line requires `classes` to be an object.

---

<div class="post-metadata">

**Author:** ![Edta](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@Edta](https://discuss.elastic.co/u/Edta)\
**Post date:** [July 21, 2017, 2:08pm UTC](https://discuss.elastic.co/t/dynamic-template-and-object-type/93968/4 "2017-07-21T14:08:10Z")

</div>

Thank for your answer.

If I understand :  
prefix : value  
prefix.XX : value  
"prefix" must be an object in my template ?

I cannot change my data (it is the endpoints "metric" of the spring boot). How can I change my template ?  
I would like each line of my data are one type in my index

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [July 21, 2017, 3:33pm UTC](https://discuss.elastic.co/t/dynamic-template-and-object-type/93968/5 "2017-07-21T15:33:05Z")

</div>

There is no way that you can make Elasticsearch accept this data, it has to be changed. Note that you could do this automatically with the ingest feature if necessary.

---

<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:** [August 18, 2017, 3:33pm UTC](https://discuss.elastic.co/t/dynamic-template-and-object-type/93968/6 "2017-08-18T15:33:38Z")

</div>

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