# Unable to query on date field

**URL:** https://discuss.elastic.co/t/unable-to-query-on-date-field/4757
**Category:** Elasticsearch
**Created:** [July 2, 2011, 8:17pm UTC](https://discuss.elastic.co/t/unable-to-query-on-date-field/4757 "2011-07-02T20:17:07Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Hari\_Shankar](https://avatars.discourse-cdn.com/v4/letter/h/ad7895/32.png) [@Hari\_Shankar](https://discuss.elastic.co/u/Hari_Shankar)
#### Post date: [July 2, 2011, 8:17pm UTC](https://discuss.elastic.co/t/unable-to-query-on-date-field/4757/1 "2011-07-02T20:17:07Z")

</div>

Hi,

I am unable to query on date type on the child mapping. Please see the gist  
here:

(Most of the stuff in between is just dummy data creation. The interesting  
part is the mapping at the top and the query results at the bottom)

> <https://gist.github.com/hshankar/1061603>

As you can see, I get the right results when I query the Impressions field,  
but I don't get any hits when I query the "Date" field. Why is that?

Hari

---

<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: [July 2, 2011, 8:26pm UTC](https://discuss.elastic.co/t/unable-to-query-on-date-field/4757/2 "2011-07-02T20:26:47Z")

</div>

Haven't run your gist, but it seems like in your query, you specify the date as a numeric value, not as a string. Can you see if it works when you have the term query run on Date as a string?

On Saturday, July 2, 2011 at 11:17 PM, Hari Shankar wrote:

> Hi,
> 
> I am unable to query on date type on the child mapping. Please see the gist here:
> 
> (Most of the stuff in between is just dummy data creation. The interesting part is the mapping at the top and the query results at the bottom)  
> [The date query returns no hits but the Impressions query works · GitHub](https://gist.github.com/1061603)
> 
> As you can see, I get the right results when I query the Impressions field, but I don't get any hits when I query the "Date" field. Why is that?
> 
> Hari

---

<div class="post-metadata">

### Author: ![Hari\_Shankar](https://avatars.discourse-cdn.com/v4/letter/h/ad7895/32.png) [@Hari\_Shankar](https://discuss.elastic.co/u/Hari_Shankar)
#### Post date: [July 2, 2011, 8:34pm UTC](https://discuss.elastic.co/t/unable-to-query-on-date-field/4757/3 "2011-07-02T20:34:35Z")

</div>

I tried putting quotes around the date in the query, but that didn't work.  
Or do you mean if I tried changing Date to string type?

On Sun, Jul 3, 2011 at 1:56 AM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> Haven't run your gist, but it seems like in your query, you specify the  
> date as a numeric value, not as a string. Can you see if it works when you  
> have the term query run on Date as a string?
> 
> On Saturday, July 2, 2011 at 11:17 PM, Hari Shankar wrote:
> 
> Hi,
> 
> I am unable to query on date type on the child mapping. Please see the gist  
> here:
> 
> (Most of the stuff in between is just dummy data creation. The interesting  
> part is the mapping at the top and the query results at the bottom)  
> [The date query returns no hits but the Impressions query works · GitHub](https://gist.github.com/1061603)
> 
> As you can see, I get the right results when I query the Impressions field,  
> but I don't get any hits when I query the "Date" field. Why is that?
> 
> Hari

---

<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: [July 2, 2011, 8:53pm UTC](https://discuss.elastic.co/t/unable-to-query-on-date-field/4757/4 "2011-07-02T20:53:08Z")

</div>

Missed that you also index the date as number. Here is a gist where you index the date as string (since its a string formatted date), and the query also uses a string for the input. The type needs to remain a string. [1061635’s gists · GitHub](https://gist.github.com/1061635)

On Saturday, July 2, 2011 at 11:34 PM, Hari Shankar wrote:

> I tried putting quotes around the date in the query, but that didn't work. Or do you mean if I tried changing Date to string type?
> 
> On Sun, Jul 3, 2011 at 1:56 AM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) ([mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com))\> wrote:
> 
> > Haven't run your gist, but it seems like in your query, you specify the date as a numeric value, not as a string. Can you see if it works when you have the term query run on Date as a string?
> > 
> > On Saturday, July 2, 2011 at 11:17 PM, Hari Shankar wrote:
> > 
> > > Hi,
> > > 
> > > I am unable to query on date type on the child mapping. Please see the gist here:
> > > 
> > > (Most of the stuff in between is just dummy data creation. The interesting part is the mapping at the top and the query results at the bottom)  
> > > [The date query returns no hits but the Impressions query works · GitHub](https://gist.github.com/1061603)
> > > 
> > > As you can see, I get the right results when I query the Impressions field, but I don't get any hits when I query the "Date" field. Why is that?
> > > 
> > > Hari

---

<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: [July 2, 2011, 8:53pm UTC](https://discuss.elastic.co/t/unable-to-query-on-date-field/4757/5 "2011-07-02T20:53:38Z")

</div>

Grr, last sentence should read: the type should remain a _date_.

On Saturday, July 2, 2011 at 11:53 PM, Shay Banon wrote:

> Missed that you also index the date as number. Here is a gist where you index the date as string (since its a string formatted date), and the query also uses a string for the input. The type needs to remain a string. [1061635’s gists · GitHub](https://gist.github.com/1061635)
> 
> On Saturday, July 2, 2011 at 11:34 PM, Hari Shankar wrote:
> 
> > I tried putting quotes around the date in the query, but that didn't work. Or do you mean if I tried changing Date to string type?
> > 
> > On Sun, Jul 3, 2011 at 1:56 AM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) ([mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com))\> wrote:
> > 
> > > Haven't run your gist, but it seems like in your query, you specify the date as a numeric value, not as a string. Can you see if it works when you have the term query run on Date as a string?
> > > 
> > > On Saturday, July 2, 2011 at 11:17 PM, Hari Shankar wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I am unable to query on date type on the child mapping. Please see the gist here:
> > > > 
> > > > (Most of the stuff in between is just dummy data creation. The interesting part is the mapping at the top and the query results at the bottom)  
> > > > [The date query returns no hits but the Impressions query works · GitHub](https://gist.github.com/1061603)
> > > > 
> > > > As you can see, I get the right results when I query the Impressions field, but I don't get any hits when I query the "Date" field. Why is that?
> > > > 
> > > > Hari

---

<div class="post-metadata">

### Author: ![Hari\_Shankar](https://avatars.discourse-cdn.com/v4/letter/h/ad7895/32.png) [@Hari\_Shankar](https://discuss.elastic.co/u/Hari_Shankar)
#### Post date: [July 3, 2011, 6:37am UTC](https://discuss.elastic.co/t/unable-to-query-on-date-field/4757/6 "2011-07-03T06:37:45Z")

</div>

Great, that works, Thanks! Is there any reason why date as integer and date  
as string are treated separately? Why doesn't the date as integer query  
work?

On Sun, Jul 3, 2011 at 2:23 AM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> Grr, last sentence should read: the type should remain a _date_.
> 
> On Saturday, July 2, 2011 at 11:53 PM, Shay Banon wrote:
> 
> Missed that you also index the date as number. Here is a gist where you  
> index the date as string (since its a string formatted date), and the query  
> also uses a string for the input. The type needs to remain a string.  
> [1061635’s gists · GitHub](https://gist.github.com/1061635)
> 
> On Saturday, July 2, 2011 at 11:34 PM, Hari Shankar wrote:
> 
> I tried putting quotes around the date in the query, but that didn't work.  
> Or do you mean if I tried changing Date to string type?
> 
> On Sun, Jul 3, 2011 at 1:56 AM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> Haven't run your gist, but it seems like in your query, you specify the  
> date as a numeric value, not as a string. Can you see if it works when you  
> have the term query run on Date as a string?
> 
> On Saturday, July 2, 2011 at 11:17 PM, Hari Shankar wrote:
> 
> Hi,
> 
> I am unable to query on date type on the child mapping. Please see the gist  
> here:
> 
> (Most of the stuff in between is just dummy data creation. The interesting  
> part is the mapping at the top and the query results at the bottom)  
> [The date query returns no hits but the Impressions query works · GitHub](https://gist.github.com/1061603)
> 
> As you can see, I get the right results when I query the Impressions field,  
> but I don't get any hits when I query the "Date" field. Why is that?
> 
> Hari

---

<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: [July 3, 2011, 6:38am UTC](https://discuss.elastic.co/t/unable-to-query-on-date-field/4757/7 "2011-07-03T06:38:58Z")

</div>

Because its a number, not the format of the date.

On Sunday, July 3, 2011 at 9:37 AM, Hari Shankar wrote:

> Great, that works, Thanks! Is there any reason why date as integer and date as string are treated separately? Why doesn't the date as integer query work?
> 
> On Sun, Jul 3, 2011 at 2:23 AM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) ([mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com))\> wrote:
> 
> > Grr, last sentence should read: the type should remain a _date_.
> > 
> > On Saturday, July 2, 2011 at 11:53 PM, Shay Banon wrote:
> > 
> > > Missed that you also index the date as number. Here is a gist where you index the date as string (since its a string formatted date), and the query also uses a string for the input. The type needs to remain a string. [1061635’s gists · GitHub](https://gist.github.com/1061635)
> > > 
> > > On Saturday, July 2, 2011 at 11:34 PM, Hari Shankar wrote:
> > > 
> > > > I tried putting quotes around the date in the query, but that didn't work. Or do you mean if I tried changing Date to string type?
> > > > 
> > > > On Sun, Jul 3, 2011 at 1:56 AM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) ([mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com))\> wrote:
> > > > 
> > > > > Haven't run your gist, but it seems like in your query, you specify the date as a numeric value, not as a string. Can you see if it works when you have the term query run on Date as a string?
> > > > > 
> > > > > On Saturday, July 2, 2011 at 11:17 PM, Hari Shankar wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > I am unable to query on date type on the child mapping. Please see the gist here:
> > > > > > 
> > > > > > (Most of the stuff in between is just dummy data creation. The interesting part is the mapping at the top and the query results at the bottom)  
> > > > > > [The date query returns no hits but the Impressions query works · GitHub](https://gist.github.com/1061603)
> > > > > > 
> > > > > > As you can see, I get the right results when I query the Impressions field, but I don't get any hits when I query the "Date" field. Why is that?
> > > > > > 
> > > > > > Hari

---

<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, 4:01am UTC](https://discuss.elastic.co/t/unable-to-query-on-date-field/4757/8 "2017-07-06T04:01:59Z")

</div>


