# Index mapping via template file

**URL:** <https://discuss.elastic.co/t/index-mapping-via-template-file/10748>\
**Category:** Elasticsearch\
**Created:** [February 14, 2013, 3:57pm UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748 "2013-02-14T15:57:56Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ulli](https://avatars.discourse-cdn.com/v4/letter/u/f04885/32.png) [@Ulli](https://discuss.elastic.co/u/Ulli)\
**Post date:** [February 14, 2013, 3:57pm UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/1 "2013-02-14T15:57:56Z")

</div>

Hi,

I'm trying to create an index mapping via template file as descirbed here:  
[http://www.elasticsearch.org/guide/reference/api/admin-indices-templates.html](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates.html)  
So I created the following template file in  
config/templates/template\_1.json:

{  
"template\_1" : {  
"template" : "\*",  
"mappings" : {  
"date" : {  
"index" : "not\_analyzed",  
"type" : "date",  
"format" : "dd/MMM/yyyy:HH:mm:ss Z"  
}  
}  
}  
}

with no effect:

curl -XGET localhost:9200/\_template/template\_1  
{}

When I put the mapping via curl request:

curl -XPUT localhost:9200/\_template/template\_1 -d '  
{  
"template" : "\*",  
"mappings" : {  
"date" : {  
"index" : "not\_analyzed",  
"type" : "date",  
"format" : "dd/MMM/yyyy:HH:mm:ss Z"  
}  
}  
}  
'

it works:

curl -XGET localhost:9200/\_template/template\_1?pretty=true  
{  
"template\_1" : {  
"template" : "\*",  
"order" : 0,  
"settings" : { },  
"mappings" : {  
"date" : {  
"index" : "not\_analyzed",  
"format" : "dd/MMM/yyyy:HH:mm:ss Z",  
"type" : "date"  
}  
}  
}  
}

So, what do I have to do to make it working via template file?

Thanks in advance  
Ulli

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ulli](https://avatars.discourse-cdn.com/v4/letter/u/f04885/32.png) [@Ulli](https://discuss.elastic.co/u/Ulli)\
**Post date:** [February 14, 2013, 4:14pm UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/2 "2013-02-14T16:14:32Z")

</div>

The configuration of path.conf was wrong but now I see an exception in the  
log:

org.elasticsearch.index.mapper.MapperParsingException: mapping [date]  
at  
org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:262)  
at  
org.elasticsearch.cluster.service.InternalClusterService$2.run(InternalClusterService.java:208)  
at  
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)  
at java.lang.Thread.run(Thread.java:679)  
Caused by: org.elasticsearch.index.mapper.MapperParsingException: Trying to  
parse an object but has a different type [date] for [date]  
at  
org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parse(ObjectMapper.java:206)  
at  
org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:161)  
at  
org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:364)  
at  
org.elasticsearch.index.mapper.MapperService.add(MapperService.java:186)  
at  
org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:259)

Am Donnerstag, 14. Februar 2013 16:57:56 UTC+1 schrieb Ulli:

> Hi,
> 
> I'm trying to create an index mapping via template file as descirbed here:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates.html)  
> So I created the following template file in  
> config/templates/template\_1.json:
> 
> {  
> "template\_1" : {  
> "template" : "\*",  
> "mappings" : {  
> "date" : {  
> "index" : "not\_analyzed",  
> "type" : "date",  
> "format" : "dd/MMM/yyyy:HH:mm:ss Z"  
> }  
> }  
> }  
> }
> 
> with no effect:
> 
> curl -XGET localhost:9200/\_template/template\_1  
> {}
> 
> When I put the mapping via curl request:
> 
> curl -XPUT localhost:9200/\_template/template\_1 -d '  
> {  
> "template" : "\*",  
> "mappings" : {  
> "date" : {  
> "index" : "not\_analyzed",  
> "type" : "date",  
> "format" : "dd/MMM/yyyy:HH:mm:ss Z"  
> }  
> }  
> }  
> '
> 
> it works:
> 
> curl -XGET localhost:9200/\_template/template\_1?pretty=true  
> {  
> "template\_1" : {  
> "template" : "\*",  
> "order" : 0,  
> "settings" : { },  
> "mappings" : {  
> "date" : {  
> "index" : "not\_analyzed",  
> "format" : "dd/MMM/yyyy:HH:mm:ss Z",  
> "type" : "date"  
> }  
> }  
> }  
> }
> 
> So, what do I have to do to make it working via template file?
> 
> Thanks in advance  
> Ulli

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ulli](https://avatars.discourse-cdn.com/v4/letter/u/f04885/32.png) [@Ulli](https://discuss.elastic.co/u/Ulli)\
**Post date:** [February 15, 2013, 10:52am UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/3 "2013-02-15T10:52:53Z")

</div>

Does anybody knows what exactly 'Trying to parse an object but has a  
different type [date] for [date]' mean?

So far I've found out that the second '[date]' is the date I configured in  
the mapping and try to index as a field. If that means that my input field  
has not the type 'date' is there a way to find out what elasticsearch  
'thinks' the type of my field is?

Am Donnerstag, 14. Februar 2013 17:14:32 UTC+1 schrieb Ulli:

> The configuration of path.conf was wrong but now I see an exception in the  
> log:
> 
> org.elasticsearch.index.mapper.MapperParsingException: mapping [date]  
> at  
> org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:262)  
> at  
> org.elasticsearch.cluster.service.InternalClusterService$2.run(InternalClusterService.java:208)  
> at  
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)  
> at java.lang.Thread.run(Thread.java:679)  
> Caused by: org.elasticsearch.index.mapper.MapperParsingException: Trying  
> to parse an object but has a different type [date] for [date]  
> at  
> org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parse(ObjectMapper.java:206)  
> at  
> org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:161)  
> at  
> org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:364)  
> at  
> org.elasticsearch.index.mapper.MapperService.add(MapperService.java:186)  
> at  
> org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:259)
> 
> Am Donnerstag, 14. Februar 2013 16:57:56 UTC+1 schrieb Ulli:
> 
> > Hi,
> > 
> > I'm trying to create an index mapping via template file as descirbed  
> > here:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates.html)  
> > So I created the following template file in  
> > config/templates/template\_1.json:
> > 
> > {  
> > "template\_1" : {  
> > "template" : "\*",  
> > "mappings" : {  
> > "date" : {  
> > "index" : "not\_analyzed",  
> > "type" : "date",  
> > "format" : "dd/MMM/yyyy:HH:mm:ss Z"  
> > }  
> > }  
> > }  
> > }
> > 
> > with no effect:
> > 
> > curl -XGET localhost:9200/\_template/template\_1  
> > {}
> > 
> > When I put the mapping via curl request:
> > 
> > curl -XPUT localhost:9200/\_template/template\_1 -d '  
> > {  
> > "template" : "\*",  
> > "mappings" : {  
> > "date" : {  
> > "index" : "not\_analyzed",  
> > "type" : "date",  
> > "format" : "dd/MMM/yyyy:HH:mm:ss Z"  
> > }  
> > }  
> > }  
> > '
> > 
> > it works:
> > 
> > curl -XGET localhost:9200/\_template/template\_1?pretty=true  
> > {  
> > "template\_1" : {  
> > "template" : "\*",  
> > "order" : 0,  
> > "settings" : { },  
> > "mappings" : {  
> > "date" : {  
> > "index" : "not\_analyzed",  
> > "format" : "dd/MMM/yyyy:HH:mm:ss Z",  
> > "type" : "date"  
> > }  
> > }  
> > }  
> > }
> > 
> > So, what do I have to do to make it working via template file?
> > 
> > Thanks in advance  
> > Ulli

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [February 16, 2013, 1:24pm UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/4 "2013-02-16T13:24:01Z")

</div>

Hello Ulli,

Elasticsearch expects a mapping type there where you put "date", not a  
field name.

So like when you store a document in  
[http://localhost:9200/test\_index/test\_type/test\_document\_ID](http://localhost:9200/test_index/test_type/test_document_ID), "test\_type" is  
your mapping type.

So your template has to be something like this:

[...]  
"mappings": {  
"type1": {  
"properties": {  
"date": {  
"type": "date"  
}  
}  
}  
}

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Fri, Feb 15, 2013 at 12:52 PM, Ulli [ulli.scheel@gmx.de](mailto:ulli.scheel@gmx.de) wrote:

> Does anybody knows what exactly 'Trying to parse an object but has a  
> different type [date] for [date]' mean?
> 
> So far I've found out that the second '[date]' is the date I configured in  
> the mapping and try to index as a field. If that means that my input field  
> has not the type 'date' is there a way to find out what elasticsearch  
> 'thinks' the type of my field is?
> 
> Am Donnerstag, 14. Februar 2013 17:14:32 UTC+1 schrieb Ulli:
> 
> > The configuration of path.conf was wrong but now I see an exception in  
> > the log:
> > 
> > org.elasticsearch.index.\*\*mapper.MapperParsingException: mapping [date]  
> > at org.elasticsearch.cluster. **metadata.**  
> > MetaDataCreateIndexService$1.\*\*execute( **MetaDataCreateIndexService.**  
> > java:262)  
> > at org.elasticsearch.cluster. **service.**  
> > InternalClusterService$2.run(\*\*InternalClusterService.java:\*\*208)  
> > at java.util.concurrent.**ThreadPoolExecutor.runWorker(**  
> > ThreadPoolExecutor.java:1110)  
> > at java.util.concurrent.**ThreadPoolExecutor$Worker.run(**  
> > ThreadPoolExecutor.java:603)  
> > at java.lang.Thread.run(Thread.\*\*java:679)  
> > Caused by: org.elasticsearch.index.\*\*mapper.MapperParsingException:  
> > Trying to parse an object but has a different type [date] for [date]  
> > at org.elasticsearch.index. **mapper.object.ObjectMapper$**  
> > TypeParser.parse(ObjectMapper.\*\*java:206)  
> > at org.elasticsearch.index. **mapper.DocumentMapperParser.**  
> > parse(DocumentMapperParser.\*\*java:161)  
> > at org.elasticsearch.index.**mapper.MapperService.parse(**  
> > MapperService.java:364)  
> > at org.elasticsearch.index.**mapper.MapperService.add(**  
> > MapperService.java:186)  
> > at org.elasticsearch.cluster. **metadata.**  
> > MetaDataCreateIndexService$1.\*\*execute( **MetaDataCreateIndexService.**  
> > java:259)
> > 
> > Am Donnerstag, 14. Februar 2013 16:57:56 UTC+1 schrieb Ulli:
> > 
> > > Hi,
> > > 
> > > I'm trying to create an index mapping via template file as descirbed  
> > > here: [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/**guide/reference/api/admin-)\*\*  
> > > indices-templates.html[http://www.elasticsearch.org/guide/reference/api/admin-indices-templates.html](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates.html)  
> > > So I created the following template file in config/templates/template\_1.  
> > > \*\*json:
> > > 
> > > {  
> > > "template\_1" : {  
> > > "template" : "\*",  
> > > "mappings" : {  
> > > "date" : {  
> > > "index" : "not\_analyzed",  
> > > "type" : "date",  
> > > "format" : "dd/MMM/yyyy:HH:mm:ss Z"  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > with no effect:
> > > 
> > > curl -XGET localhost:9200/\_template/\*\*template\_1  
> > > {}
> > > 
> > > When I put the mapping via curl request:
> > > 
> > > curl -XPUT localhost:9200/\_template/\*\*template\_1 -d '  
> > > {  
> > > "template" : "\*",  
> > > "mappings" : {  
> > > "date" : {  
> > > "index" : "not\_analyzed",  
> > > "type" : "date",  
> > > "format" : "dd/MMM/yyyy:HH:mm:ss Z"  
> > > }  
> > > }  
> > > }  
> > > '
> > > 
> > > it works:
> > > 
> > > curl -XGET localhost:9200/\_template/\*\*template\_1?pretty=true  
> > > {  
> > > "template\_1" : {  
> > > "template" : "\*",  
> > > "order" : 0,  
> > > "settings" : { },  
> > > "mappings" : {  
> > > "date" : {  
> > > "index" : "not\_analyzed",  
> > > "format" : "dd/MMM/yyyy:HH:mm:ss Z",  
> > > "type" : "date"  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > So, what do I have to do to make it working via template file?
> > > 
> > > Thanks in advance  
> > > Ulli
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ulli](https://avatars.discourse-cdn.com/v4/letter/u/f04885/32.png) [@Ulli](https://discuss.elastic.co/u/Ulli)\
**Post date:** [February 18, 2013, 11:27am UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/5 "2013-02-18T11:27:45Z")

</div>

Thank you, Radu. It looks better know. I don't see any exceptions in the  
log any more. But a range search on the date field doesn't work.

This is what my mapping looks like now:

{  
"template\_1" : {  
"template" : "\*",  
"access-log" : {  
"properties" : {  
"date" : {  
"index" : "not\_analyzed",  
"type" : "date",  
"format" : "dd/MMM/yyyy:HH:mm:ss Z"  
}  
}  
}  
}  
}

I indexed one document with field that has the date "12/Sep/2012:11:24:02  
+0200"  
But the following range search has 0 hits:

curl -XGET '[http://localhost:9200/\_search?pretty=true](http://localhost:9200/_search?pretty=true)' -d '{  
"query":{  
"bool":{  
"must":[  
{  
"range":{  
"accessdate":{  
"from":"12/Sep/2012:11:24:00 +0200",  
"to":"12/Sep/2012:11:24:05 +0200"  
}  
}  
}  
]  
}  
}  
}'

But this search finds the document:

curl -XGET '[http://localhost:9200/\_search?pretty=true](http://localhost:9200/_search?pretty=true)' -d '{  
"query":{  
"bool":{  
"must":[  
{  
"range":{  
"accessdate":{  
"from":"10/Sep/2012:23:59:59 +0200",  
"to":"11/Sep/2012:00:00:00 +0200"  
}  
}  
}  
]  
}  
}  
}'

It seems that search is successful when the dates have different days  
regardless of what is indexed. I tried to find out the 'real' date in the  
index is:

curl'[http://localhost:9200/\_all0/\_search?pretty=true](http://localhost:9200/_all0/_search?pretty=true)' -d '{  
"query" : {  
"match\_all" : { }  
},  
"script\_fields": {  
"terms" : {  
"script": "doc[field].values",  
"params": {  
"field": "accessdate"  
}  
}  
}  
}'  
{  
"took" : 2,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "logstash-2013.02.18",  
"\_type" : "access-log",  
"\_id" : "apV2kN7pT8yFmmFnT\_W\_Mg",  
"\_score" : 1.0,  
"fields" : {  
"terms" : ["02", "0200", "11", "12", "2012", "24", "sep"]  
}  
} ]  
}  
}

I don't know if this is something I can rely on. The date in the index  
should be stored as milliseconds since epoche, right? Does this output  
means my date is not stored as a date?

Am Samstag, 16. Februar 2013 14:24:01 UTC+1 schrieb Radu Gheorghe:

> Hello Ulli,
> 
> Elasticsearch expects a mapping type there where you put "date", not a  
> field name.
> 
> So like when you store a document in  
> [http://localhost:9200/test\_index/test\_type/test\_document\_ID](http://localhost:9200/test_index/test_type/test_document_ID), "test\_type"  
> is your mapping type.
> 
> So your template has to be something like this:
> 
> [...]  
> "mappings": {  
> "type1": {  
> "properties": {  
> "date": {  
> "type": "date"  
> }  
> }  
> }  
> }
> 
> ## Best regards, Radu
> 
> [http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene
> 
> On Fri, Feb 15, 2013 at 12:52 PM, Ulli \<[ulli....@gmx.de](mailto:ulli....@gmx.de) \<javascript:\>\>wrote:
> 
> > Does anybody knows what exactly 'Trying to parse an object but has a  
> > different type [date] for [date]' mean?
> > 
> > So far I've found out that the second '[date]' is the date I configured  
> > in the mapping and try to index as a field. If that means that my input  
> > field has not the type 'date' is there a way to find out what elasticsearch  
> > 'thinks' the type of my field is?
> > 
> > Am Donnerstag, 14. Februar 2013 17:14:32 UTC+1 schrieb Ulli:
> > 
> > > The configuration of path.conf was wrong but now I see an exception in  
> > > the log:
> > > 
> > > org.elasticsearch.index.\*\*mapper.MapperParsingException: mapping [date]  
> > > at org.elasticsearch.cluster. **metadata.**  
> > > MetaDataCreateIndexService$1.\*\*execute( **MetaDataCreateIndexService.**  
> > > java:262)  
> > > at org.elasticsearch.cluster. **service.**  
> > > InternalClusterService$2.run(\*\*InternalClusterService.java:\*\*208)  
> > > at java.util.concurrent.**ThreadPoolExecutor.runWorker(**  
> > > ThreadPoolExecutor.java:1110)  
> > > at java.util.concurrent.**ThreadPoolExecutor$Worker.run(**  
> > > ThreadPoolExecutor.java:603)  
> > > at java.lang.Thread.run(Thread.\*\*java:679)  
> > > Caused by: org.elasticsearch.index.\*\*mapper.MapperParsingException:  
> > > Trying to parse an object but has a different type [date] for [date]  
> > > at org.elasticsearch.index. **mapper.object.ObjectMapper$**  
> > > TypeParser.parse(ObjectMapper.\*\*java:206)  
> > > at org.elasticsearch.index. **mapper.DocumentMapperParser.**  
> > > parse(DocumentMapperParser.\*\*java:161)  
> > > at org.elasticsearch.index.**mapper.MapperService.parse(**  
> > > MapperService.java:364)  
> > > at org.elasticsearch.index.**mapper.MapperService.add(**  
> > > MapperService.java:186)  
> > > at org.elasticsearch.cluster. **metadata.**  
> > > MetaDataCreateIndexService$1.\*\*execute( **MetaDataCreateIndexService.**  
> > > java:259)
> > > 
> > > Am Donnerstag, 14. Februar 2013 16:57:56 UTC+1 schrieb Ulli:
> > > 
> > > > Hi,
> > > > 
> > > > I'm trying to create an index mapping via template file as descirbed  
> > > > here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/**guide/reference/api/admin-)\*\*  
> > > > indices-templates.html[http://www.elasticsearch.org/guide/reference/api/admin-indices-templates.html](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates.html)  
> > > > So I created the following template file in config/templates/template\_1.  
> > > > \*\*json:
> > > > 
> > > > {  
> > > > "template\_1" : {  
> > > > "template" : "\*",  
> > > > "mappings" : {  
> > > > "date" : {  
> > > > "index" : "not\_analyzed",  
> > > > "type" : "date",  
> > > > "format" : "dd/MMM/yyyy:HH:mm:ss Z"  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > with no effect:
> > > > 
> > > > curl -XGET localhost:9200/\_template/\*\*template\_1  
> > > > {}
> > > > 
> > > > When I put the mapping via curl request:
> > > > 
> > > > curl -XPUT localhost:9200/\_template/\*\*template\_1 -d '  
> > > > {  
> > > > "template" : "\*",  
> > > > "mappings" : {  
> > > > "date" : {  
> > > > "index" : "not\_analyzed",  
> > > > "type" : "date",  
> > > > "format" : "dd/MMM/yyyy:HH:mm:ss Z"  
> > > > }  
> > > > }  
> > > > }  
> > > > '
> > > > 
> > > > it works:
> > > > 
> > > > curl -XGET localhost:9200/\_template/\*\*template\_1?pretty=true  
> > > > {  
> > > > "template\_1" : {  
> > > > "template" : "\*",  
> > > > "order" : 0,  
> > > > "settings" : { },  
> > > > "mappings" : {  
> > > > "date" : {  
> > > > "index" : "not\_analyzed",  
> > > > "format" : "dd/MMM/yyyy:HH:mm:ss Z",  
> > > > "type" : "date"  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > So, what do I have to do to make it working via template file?
> > > > 
> > > > Thanks in advance  
> > > > Ulli
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ulli](https://avatars.discourse-cdn.com/v4/letter/u/f04885/32.png) [@Ulli](https://discuss.elastic.co/u/Ulli)\
**Post date:** [February 19, 2013, 8:53am UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/6 "2013-02-19T08:53:03Z")

</div>

Obviously the mapping is not enough:

curl -XGET '[http://localhost:9200/\_all/\_mapping?pretty=true](http://localhost:9200/_all/_mapping?pretty=true)'  
{  
"logstash-2013.02.18" : {  
"access-log" : {  
"properties" : {  
"@fields" : {  
"dynamic" : "true",  
"properties" : {  
"ZONE" : {  
"type" : "string"  
},  
"accessdate" : {  
"type" : "string"  
},  
...

Do I have to tell elasticsearch that my date field 'accessdate' is of type  
date? How?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [February 19, 2013, 1:24pm UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/7 "2013-02-19T13:24:56Z")

</div>

Hello Ulli,

Yes, you have to tell Elasticsearch that your accessdate field is date.  
That's what you define in your mapping.

Please note that you also need to point to the specific field in your  
query. So '@fields.accessdate' instead of just 'accessdate'.

I've put together a gist with a sample mapping and sample query that should  
work. I didn't get to test them, so if there are mistakes please let me  
know.

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Tue, Feb 19, 2013 at 10:53 AM, Ulli [ulli.scheel@gmx.de](mailto:ulli.scheel@gmx.de) wrote:

> Obviously the mapping is not enough:
> 
> curl -XGET '[http://localhost:9200/\_all/\_mapping?pretty=true](http://localhost:9200/_all/_mapping?pretty=true)'  
> {  
> "logstash-2013.02.18" : {  
> "access-log" : {  
> "properties" : {  
> "@fields" : {  
> "dynamic" : "true",  
> "properties" : {  
> "ZONE" : {  
> "type" : "string"  
> },  
> "accessdate" : {  
> "type" : "string"  
> },  
> ...
> 
> Do I have to tell elasticsearch that my date field 'accessdate' is of type  
> date? How?
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ulli](https://avatars.discourse-cdn.com/v4/letter/u/f04885/32.png) [@Ulli](https://discuss.elastic.co/u/Ulli)\
**Post date:** [February 19, 2013, 1:44pm UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/8 "2013-02-19T13:44:58Z")

</div>

Am Dienstag, 19. Februar 2013 14:24:56 UTC+1 schrieb Radu Gheorghe:

> I've put together a gist with a sample mapping and sample query that  
> should work.

Thank you. Where do I find it?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [February 19, 2013, 2:58pm UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/9 "2013-02-19T14:58:29Z")

</div>

Jeez, forgot to put the link. Sorry. Here you go:

> <https://gist.github.com/radu-gheorghe/4985795>

On Tue, Feb 19, 2013 at 3:44 PM, Ulli [ulli.scheel@gmx.de](mailto:ulli.scheel@gmx.de) wrote:

> Am Dienstag, 19. Februar 2013 14:24:56 UTC+1 schrieb Radu Gheorghe:
> 
> > I've put together a gist with a sample mapping and sample query that  
> > should work.
> 
> Thank you. Where do I find it?
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ulli](https://avatars.discourse-cdn.com/v4/letter/u/f04885/32.png) [@Ulli](https://discuss.elastic.co/u/Ulli)\
**Post date:** [February 19, 2013, 3:58pm UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/10 "2013-02-19T15:58:18Z")

</div>

So, when I put your sample into my template file as described in my  
original posting I should see 'accessdate' as type date when using curl  
-XGET '[http://localhost:9200/\_all/\_mapping?pretty=true](http://localhost:9200/_all/_mapping?pretty=true)'?  
It's still a string:

curl -XGET '[http://localhost:9200/\_all/\_mapping?pretty=true](http://localhost:9200/_all/_mapping?pretty=true)'  
{  
"logstash-2013.02.19" : {  
"access-log" : {  
"properties" : {  
"@fields" : {  
"dynamic" : "true",  
"properties" : {  
"ZONE" : {  
"type" : "string"  
},  
"accessdate" : {  
"type" : "string"  
},  
...

Am Dienstag, 19. Februar 2013 15:58:29 UTC+1 schrieb Radu Gheorghe:

> Jeez, forgot to put the link. Sorry. Here you go:  
> [logstash\_date\_mapping.json · GitHub](https://gist.github.com/radu-gheorghe/4985795)
> 
> On Tue, Feb 19, 2013 at 3:44 PM, Ulli \<[ulli....@gmx.de](mailto:ulli....@gmx.de) \<javascript:\>\>wrote:
> 
> > Am Dienstag, 19. Februar 2013 14:24:56 UTC+1 schrieb Radu Gheorghe:
> > 
> > > I've put together a gist with a sample mapping and sample query that  
> > > should work.
> > 
> > Thank you. Where do I find it?
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> [http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [February 19, 2013, 6:09pm UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/11 "2013-02-19T18:09:41Z")

</div>

Hello Ulli,

When you change your mapping, you need to remove your data (indices) and  
reindex that data. The template will only be applied when a new index (that  
matches the template name) is created.

You can "extend" the mapping by using the Put Mapping API:

> **[Elastic — The Search AI Company](https://www.elastic.co)**
>
> Power insights and outcomes with The Elastic Search AI Platform. See into your data and find answers that matter with enterprise solutions designed to help you accelerate time to insight. Try Elastic ...

But even then, you can change a field's type without reindexing.

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Tue, Feb 19, 2013 at 5:58 PM, Ulli [ulli.scheel@gmx.de](mailto:ulli.scheel@gmx.de) wrote:

> So, when I put your sample into my template file as described in my  
> original posting I should see 'accessdate' as type date when using curl  
> -XGET '[http://localhost:9200/\_all/\_mapping?pretty=true](http://localhost:9200/_all/_mapping?pretty=true)'?  
> It's still a string:
> 
> curl -XGET '[http://localhost:9200/\_all/\_mapping?pretty=true](http://localhost:9200/_all/_mapping?pretty=true)'  
> {  
> "logstash-2013.02.19" : {
> 
> ```
> "access-log" : {
> "properties" : {
> "@fields" : {
> "dynamic" : "true",
> "properties" : {
> "ZONE" : {
> "type" : "string"
> },
> "accessdate" : {
> "type" : "string"
> },
> ...
> 
> ```
> 
> Am Dienstag, 19. Februar 2013 15:58:29 UTC+1 schrieb Radu Gheorghe:
> 
> > Jeez, forgot to put the link. Sorry. Here you go:  
> > [https://gist.github.com/radu-\*\*gheorghe/4985795](https://gist.github.com/radu-**gheorghe/4985795)[https://gist.github.com/radu-gheorghe/4985795](https://gist.github.com/radu-gheorghe/4985795)
> > 
> > On Tue, Feb 19, 2013 at 3:44 PM, Ulli [ulli....@gmx.de](mailto:ulli....@gmx.de) wrote:
> > 
> > > Am Dienstag, 19. Februar 2013 14:24:56 UTC+1 schrieb Radu Gheorghe:
> > > 
> > > > I've put together a gist with a sample mapping and sample query that  
> > > > should work.
> > > 
> > > Thank you. Where do I find it?
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > .
> > 
> > --  
> > [http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ulli](https://avatars.discourse-cdn.com/v4/letter/u/f04885/32.png) [@Ulli](https://discuss.elastic.co/u/Ulli)\
**Post date:** [February 20, 2013, 8:43am UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/12 "2013-02-20T08:43:45Z")

</div>

Am Dienstag, 19. Februar 2013 19:09:41 UTC+1 schrieb Radu Gheorghe:

> When you change your mapping, you need to remove your data (indices) and  
> reindex that data.

I know, I did it.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ulli](https://avatars.discourse-cdn.com/v4/letter/u/f04885/32.png) [@Ulli](https://discuss.elastic.co/u/Ulli)\
**Post date:** [February 20, 2013, 9:55am UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/13 "2013-02-20T09:55:57Z")

</div>

Is there a way to verify that the template file is actually used by  
elasticsearch?

Am Mittwoch, 20. Februar 2013 09:43:45 UTC+1 schrieb Ulli:

> Am Dienstag, 19. Februar 2013 19:09:41 UTC+1 schrieb Radu Gheorghe:
> 
> > When you change your mapping, you need to remove your data (indices) and  
> > reindex that data.
> 
> I know, I did it.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [February 20, 2013, 1:07pm UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/14 "2013-02-20T13:07:21Z")

</div>

Hello Ulli,

The only way I'm aware of is to test it: create an index that matches the  
template and get the mapping for the type you're interested in.

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Wed, Feb 20, 2013 at 11:55 AM, Ulli [ulli.scheel@gmx.de](mailto:ulli.scheel@gmx.de) wrote:

> Is there a way to verify that the template file is actually used by  
> elasticsearch?
> 
> Am Mittwoch, 20. Februar 2013 09:43:45 UTC+1 schrieb Ulli:
> 
> > Am Dienstag, 19. Februar 2013 19:09:41 UTC+1 schrieb Radu Gheorghe:
> > 
> > > When you change your mapping, you need to remove your data (indices) and  
> > > reindex that data.
> > 
> > I know, I did it.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ulli](https://avatars.discourse-cdn.com/v4/letter/u/f04885/32.png) [@Ulli](https://discuss.elastic.co/u/Ulli)\
**Post date:** [February 21, 2013, 4:26pm UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/15 "2013-02-21T16:26:40Z")

</div>

This[http://untergeek.com/2012/10/12/using-elasticsearch-mappings-appropriately-to-map-as-type-ip-int-float-etc/](http://untergeek.com/2012/10/12/using-elasticsearch-mappings-appropriately-to-map-as-type-ip-int-float-etc/)helped my to get it work with 'curl XPUT'. This it what it looks now:

Code hier eingeben...curl -XPUT [http://localhost:9200/\_template/logstash\_per\_index](http://localhost:9200/_template/logstash_per_index)  
-d '{  
"template" : "logstash\*",  
"mappings" : {  
"_default_" : {  
"\_all" : {"enabled" : false},  
"properties" : {  
"@fields" : {  
"type" : "object",  
"dynamic": true,  
"path": "full",  
"properties" : {  
"accessdate" : {  
"index" : "not\_analyzed",  
"type" : "date",  
"format" : "dd/MMM/yyyy:HH:mm:ss Z"  
}  
}  
},  
"@message": { "type": "string", "index": "analyzed" },  
"@source": { "type": "string", "index": "not\_analyzed" },  
"@source\_host": { "type": "string", "index": "not\_analyzed" },  
"@source\_path": { "type": "string", "index": "not\_analyzed" },  
"@tags": { "type": "string", "index": "not\_analyzed" },  
"@timestamp": { "type": "date", "index": "not\_analyzed" },  
"@type": { "type": "string", "index": "not\_analyzed" }  
}  
}  
}  
}  
'

But I'm still trying to get it work with a template file. There are many  
different and contradictory statements about where to place it and how to  
name it, e.g.:

- config/default-mapping.json
- config/mappings/\_default/.json
- config/mappings/.json
- ...

So, what is the right way? If there is used in a file name is it the  
index type or the data type? Does the root element in the config file has  
to be the type (which one again)?

Thanks in advance to anyone that gets my out of this confusion.  
Ulli

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:50am UTC](https://discuss.elastic.co/t/index-mapping-via-template-file/10748/16 "2017-07-06T02:50:16Z")

</div>


