{"action":"created","issue":{"url":"https://api.github.com/repos/sksamuel/elastic4s/issues/249","labels_url":"https://api.github.com/repos/sksamuel/elastic4s/issues/249/labels{/name}","comments_url":"https://api.github.com/repos/sksamuel/elastic4s/issues/249/comments","events_url":"https://api.github.com/repos/sksamuel/elastic4s/issues/249/events","html_url":"https://github.com/sksamuel/elastic4s/issues/249","id":50268540,"number":249,"title":"Index template creates MapperParsingException","user":{"login":"MLnick","id":1036807,"avatar_url":"https://avatars.githubusercontent.com/u/1036807?v=3","gravatar_id":"","url":"https://api.github.com/users/MLnick","html_url":"https://github.com/MLnick","followers_url":"https://api.github.com/users/MLnick/followers","following_url":"https://api.github.com/users/MLnick/following{/other_user}","gists_url":"https://api.github.com/users/MLnick/gists{/gist_id}","starred_url":"https://api.github.com/users/MLnick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MLnick/subscriptions","organizations_url":"https://api.github.com/users/MLnick/orgs","repos_url":"https://api.github.com/users/MLnick/repos","events_url":"https://api.github.com/users/MLnick/events{/privacy}","received_events_url":"https://api.github.com/users/MLnick/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2014-11-27T09:05:46Z","updated_at":"2015-01-11T08:02:39Z","closed_at":"2015-01-09T18:18:05Z","body":"Creating an index template and then trying to index into a new index results in the following error:\r\n\r\n```\r\nException in thread \"main\" org.elasticsearch.transport.RemoteTransportException: [Vermin][inet[/127.0.0.1:9300]][indices:data/write/index]\r\nCaused by: org.elasticsearch.index.mapper.MapperParsingException: mapping []\r\n\tat org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$2.execute(MetaDataCreateIndexService.java:405)\r\n\tat org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:329)\r\n\tat org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:153)\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)\r\n\tat java.lang.Thread.run(Thread.java:745)\r\nCaused by: org.elasticsearch.index.mapper.MapperParsingException: Root type mapping not empty after parsing! Remaining fields:   [city : {dynamic=dynamic, _source={enabled=true}, numeric_detection=true, _ttl={enabled=false}, properties={location={type=geo_point}, year_founded={type=integer}}, _all={enabled=true}}]\r\n\tat org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:276)\r\n\tat org.elasticsearch.index.mapper.DocumentMapperParser.parseCompressed(DocumentMapperParser.java:190)\r\n\tat org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:444)\r\n\tat org.elasticsearch.index.mapper.MapperService.merge(MapperService.java:317)\r\n\tat org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$2.execute(MetaDataCreateIndexService.java:402)\r\n\t... 5 more\r\n```\r\n\r\nCan re-create like:\r\n\r\n```scala\r\nobject ESTest extends App {\r\n  import com.sksamuel.elastic4s.ElasticDsl._\r\n  import scala.concurrent.duration._\r\n  val client = ElasticClient.remote(\"127.0.0.1\", 9300)\r\n\r\n\r\n  val f = client.execute {\r\n      create template \"some_template\" pattern \"*\" mappings (\r\n      \"city\" as (\r\n        \"year_founded\" typed IntegerType,\r\n        \"location\" typed GeoPointType\r\n        )\r\n      )\r\n  }\r\n  f.await(1 second)\r\n  val r = client.execute {\r\n    index into \"test\" -> \"city\" fields (\r\n      \"year_founded\" -> 1829,\r\n      \"location\" -> \"33.9253, 18.4239\"\r\n      )\r\n  }\r\n\r\n  r.await(1 second)\r\n\r\n}\r\n```\r\n\r\nThe problem is that the template created looks like this:\r\n\r\n```json\r\n{\r\n  \"some_template\" : {\r\n    \"order\" : 0,\r\n    \"template\" : \"*\",\r\n    \"settings\" : { },\r\n    \"mappings\" : {\r\n      \"\" : {\r\n        \"city\" : {\r\n          \"dynamic\" : \"dynamic\",\r\n          \"_source\" : {\r\n            \"enabled\" : true\r\n          },\r\n          \"numeric_detection\" : true,\r\n          \"_ttl\" : {\r\n            \"enabled\" : false\r\n          },\r\n          \"properties\" : {\r\n            \"location\" : {\r\n              \"type\" : \"geo_point\"\r\n            },\r\n            \"year_founded\" : {\r\n              \"type\" : \"integer\"\r\n            }\r\n          },\r\n          \"_all\" : {\r\n            \"enabled\" : true\r\n          }\r\n        }\r\n      }\r\n    },\r\n    \"aliases\" : { }\r\n  }\r\n}\r\n```\r\n\r\nUnder mappings the first element is a blank `\"\"`. This derives from the following line: https://github.com/sksamuel/elastic4s/blob/b96f3aee5f91baecd745bc993a59f090a26895ce/src/main/scala/com/sksamuel/elastic4s/admin/IndexTemplateDsl.scala#L25\r\n\r\nIt seems like the call should be ``` _builder.addMapping(TYPE, mapping.build.SUB_MAPPING)```. I played around with it a bit but couldn't figure out how to achieve this (I'm not familiar with the XContent builder etc).\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/sksamuel/elastic4s/issues/comments/69486785","html_url":"https://github.com/sksamuel/elastic4s/issues/249#issuecomment-69486785","issue_url":"https://api.github.com/repos/sksamuel/elastic4s/issues/249","id":69486785,"user":{"login":"MLnick","id":1036807,"avatar_url":"https://avatars.githubusercontent.com/u/1036807?v=3","gravatar_id":"","url":"https://api.github.com/users/MLnick","html_url":"https://github.com/MLnick","followers_url":"https://api.github.com/users/MLnick/followers","following_url":"https://api.github.com/users/MLnick/following{/other_user}","gists_url":"https://api.github.com/users/MLnick/gists{/gist_id}","starred_url":"https://api.github.com/users/MLnick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MLnick/subscriptions","organizations_url":"https://api.github.com/users/MLnick/orgs","repos_url":"https://api.github.com/users/MLnick/repos","events_url":"https://api.github.com/users/MLnick/events{/privacy}","received_events_url":"https://api.github.com/users/MLnick/received_events","type":"User","site_admin":false},"created_at":"2015-01-11T08:02:39Z","updated_at":"2015-01-11T08:02:39Z","body":"`sbt test` passes for me now too. I will test it out on my local ES setup also.\r\nThanks!"}}