# Making date field work

**URL:** https://discuss.elastic.co/t/making-date-field-work/5207
**Category:** Elasticsearch
**Created:** [August 20, 2011, 5:00pm UTC](https://discuss.elastic.co/t/making-date-field-work/5207 "2011-08-20T17:00:36Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![mfeingold](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@mfeingold](https://discuss.elastic.co/u/mfeingold)
#### Post date: [August 20, 2011, 5:00pm UTC](https://discuss.elastic.co/t/making-date-field-work/5207/1 "2011-08-20T17:00:36Z")

</div>

Is there a trick to making date field work? I tried a few things to no  
avail here is what I tried:

1. I mapped the field specifying field type as "date" - no explicit  
definition for analyzer. I indexed a few records with the date  
formatted as yyyy-mm-dd and I tried to run both term and text queries  
providing date in the same format. Again without explicitly specifying  
the analyzer. Both queries came back empty even though when I pulled  
the documents using queries based on different fields I can see the  
date is there
2. I did pretty much the same but changed the field type to "string"  
with the same result.

What am I missing here?

---

<div class="post-metadata">

### Author: ![avasilenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avasilenko/32/2901_2.png) [@avasilenko](https://discuss.elastic.co/u/avasilenko)
#### Post date: [August 22, 2011, 7:03am UTC](https://discuss.elastic.co/t/making-date-field-work/5207/2 "2011-08-22T07:03:43Z")

</div>

There was a fix in 0.17.6 -

> **[Issues · elastic/elasticsearch](https://github.com/elastic/elasticsearch/issues?q=is%3Aclosed%2Bsort%3Acreated-desc%2Blabel%3Av0.17.6)**
>
> Free and Open, Distributed, RESTful Search Engine. Contribute to elastic/elasticsearch development by creating an account on GitHub.

.  
Please specify the version, you're using.  
Alexandr Vasilenko

2011/8/20 Michael Feingold [mfeingold@hill30.com](mailto:mfeingold@hill30.com)

> Is there a trick to making date field work? I tried a few things to no  
> avail here is what I tried:
> 
> 1. I mapped the field specifying field type as "date" - no explicit  
> definition for analyzer. I indexed a few records with the date  
> formatted as yyyy-mm-dd and I tried to run both term and text queries  
> providing date in the same format. Again without explicitly specifying  
> the analyzer. Both queries came back empty even though when I pulled  
> the documents using queries based on different fields I can see the  
> date is there
> 2. I did pretty much the same but changed the field type to "string"  
> with the same result.
> 
> What am I missing here?

---

<div class="post-metadata">

### Author: ![mfeingold](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@mfeingold](https://discuss.elastic.co/u/mfeingold)
#### Post date: [August 22, 2011, 3:43pm UTC](https://discuss.elastic.co/t/making-date-field-work/5207/3 "2011-08-22T15:43:36Z")

</div>

I am currently on 0.17.2. Which one should I be using?

On Aug 22, 2:03 am, Alex Vasilenko [aa.vasile...@gmail.com](mailto:aa.vasile...@gmail.com) wrote:

> There was a fix in 0.17.6 -[Issues · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues?labels=v0.17.6&)...  
> .  
> Please specify the version, you're using.  
> Alexandr Vasilenko
> 
> 2011/8/20 Michael Feingold [mfeing...@hill30.com](mailto:mfeing...@hill30.com)
> 
> > Is there a trick to making date field work? I tried a few things to no  
> > avail here is what I tried:
> 
> > 1. I mapped the field specifying field type as "date" - no explicit  
> > definition for analyzer. I indexed a few records with the date  
> > formatted as yyyy-mm-dd and I tried to run both term and text queries  
> > providing date in the same format. Again without explicitly specifying  
> > the analyzer. Both queries came back empty even though when I pulled  
> > the documents using queries based on different fields I can see the  
> > date is there
> > 2. I did pretty much the same but changed the field type to "string"  
> > with the same result.
> 
> > What am I missing here?

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [August 22, 2011, 6:50pm UTC](https://discuss.elastic.co/t/making-date-field-work/5207/4 "2011-08-22T18:50:45Z")

</div>

The format that you use is not affected by the mentioned problem (but, you  
should upgrade in any case to latest). Back to your question, can you post a  
simpel recreation of what does not work? If you index a field  
with the yyyy-MM-dd format, it will automatically be detected as date type,  
so you don't even need to explicitly specify it as date. Also, when working  
with dates, there isn't really a meaning for an analyzer.

On Mon, Aug 22, 2011 at 6:43 PM, Michael Feingold [mfeingold@hill30.com](mailto:mfeingold@hill30.com)wrote:

> I am currently on 0.17.2. Which one should I be using?
> 
> On Aug 22, 2:03 am, Alex Vasilenko [aa.vasile...@gmail.com](mailto:aa.vasile...@gmail.com) wrote:
> 
> > There was a fix in 0.17.6 -  
> > [Issues · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues?labels=v0.17.6&)...  
> > .  
> > Please specify the version, you're using.  
> > Alexandr Vasilenko
> > 
> > 2011/8/20 Michael Feingold [mfeing...@hill30.com](mailto:mfeing...@hill30.com)
> > 
> > > Is there a trick to making date field work? I tried a few things to no  
> > > avail here is what I tried:
> > 
> > > 1. I mapped the field specifying field type as "date" - no explicit  
> > > definition for analyzer. I indexed a few records with the date  
> > > formatted as yyyy-mm-dd and I tried to run both term and text queries  
> > > providing date in the same format. Again without explicitly specifying  
> > > the analyzer. Both queries came back empty even though when I pulled  
> > > the documents using queries based on different fields I can see the  
> > > date is there
> > > 2. I did pretty much the same but changed the field type to "string"  
> > > with the same result.
> > 
> > > What am I missing here?

---

<div class="post-metadata">

### Author: ![mfeingold](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@mfeingold](https://discuss.elastic.co/u/mfeingold)
#### Post date: [August 29, 2011, 4:18pm UTC](https://discuss.elastic.co/t/making-date-field-work/5207/5 "2011-08-29T16:18:30Z")

</div>

Well, it is embarrassing. After several days of on and off poking  
around, I figured it out. It turns out that if the case of the field  
name you use in both mapping and query does not match the case of the  
"same" name in the json with the data, the "mapped" field stays empty  
and searches against it come back empty too.

Lesson learned. But to make it easier on other people - would it make  
sense to introduce a way to make upload "strict" - meaning that all  
fields in the data json have to be mapped upfront. That's the mode I  
would use and it would definitely save me some grief.

On Aug 22, 1:50 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> The format that you use is not affected by the mentioned problem (but, you  
> should upgrade in any case to latest). Back to your question, can you post a  
> simpel recreation of what does not work? If you index a field  
> with the yyyy-MM-dd format, it will automatically be detected as date type,  
> so you don't even need to explicitly specify it as date. Also, when working  
> with dates, there isn't really a meaning for an analyzer.
> 
> On Mon, Aug 22, 2011 at 6:43 PM, Michael Feingold [mfeing...@hill30.com](mailto:mfeing...@hill30.com)wrote:
> 
> > I am currently on 0.17.2. Which one should I be using?
> 
> > On Aug 22, 2:03 am, Alex Vasilenko [aa.vasile...@gmail.com](mailto:aa.vasile...@gmail.com) wrote:
> > 
> > > There was a fix in 0.17.6 -  
> > > [Issues · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues?labels=v0.17.6&)...  
> > > .  
> > > Please specify the version, you're using.  
> > > Alexandr Vasilenko
> 
> > > 2011/8/20 Michael Feingold [mfeing...@hill30.com](mailto:mfeing...@hill30.com)
> 
> > > > Is there a trick to making date field work? I tried a few things to no  
> > > > avail here is what I tried:
> 
> > > > 1. I mapped the field specifying field type as "date" - no explicit  
> > > > definition for analyzer. I indexed a few records with the date  
> > > > formatted as yyyy-mm-dd and I tried to run both term and text queries  
> > > > providing date in the same format. Again without explicitly specifying  
> > > > the analyzer. Both queries came back empty even though when I pulled  
> > > > the documents using queries based on different fields I can see the  
> > > > date is there
> > > > 2. I did pretty much the same but changed the field type to "string"  
> > > > with the same result.
> 
> > > > What am I missing here?

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [August 29, 2011, 4:40pm UTC](https://discuss.elastic.co/t/making-date-field-work/5207/6 "2011-08-29T16:40:22Z")

</div>

Hi Michael

> Lesson learned. But to make it easier on other people - would it make  
> sense to introduce a way to make upload "strict" - meaning that all  
> fields in the data json have to be mapped upfront. That's the mode I  
> would use and it would definitely save me some grief.

Have a look at the { dynamic: "strict" } setting on this page:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

clint

---

<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, 3:55am UTC](https://discuss.elastic.co/t/making-date-field-work/5207/7 "2017-07-06T03:55:43Z")

</div>


