# Date range query

**URL:** https://discuss.elastic.co/t/date-range-query/2930
**Category:** Elasticsearch
**Created:** [April 27, 2010, 8:00pm UTC](https://discuss.elastic.co/t/date-range-query/2930 "2010-04-27T20:00:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![talsalmona](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/talsalmona/32/3316_2.png) [@talsalmona](https://discuss.elastic.co/u/talsalmona)
#### Post date: [April 27, 2010, 8:00pm UTC](https://discuss.elastic.co/t/date-range-query/2930/1 "2010-04-27T20:00:32Z")

</div>

Hi,

I have an index that was created with the following calls:  
curl -XPUT '[http://localhost:9200/t/o/1](http://localhost:9200/t/o/1)' -d '{name:"May 1st",  
date:"2010-05-01"}'  
curl -XPUT '[http://localhost:9200/t/o/2](http://localhost:9200/t/o/2)' -d '{name:"May 2nd",  
date:"2010-05-02"}'  
curl -XPUT '[http://localhost:9200/t/o/3](http://localhost:9200/t/o/3)' -d '{name:"May 3rd",  
date:"2010-05-03"}'

The date field in the schema is correctly created and looks like this:  
"date" : {  
"type" : "date",  
"index\_name" : "date",  
"index" : "not\_analyzed",  
"store" : "no",  
"term\_vector" : "no",  
"boost" : 1.0,  
"omit\_norms" : true,  
"omit\_term\_freq\_and\_positions" : true,  
"precision\_step" : 4,  
"format" : "dateOptionalTime"  
}

When I do this query:  
curl -XGET '[http://localhost:9200/t/o/\_search?q=date:2010-05-01](http://localhost:9200/t/o/_search?q=date:2010-05-01)'

I get the expected results:  
{"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":  
1,"hits":[{"\_index":"t","\_type":"o","\_id":"1", "\_source" : {name:"May  
1st", date:"2010-05-01"}}]}}

When I do this query:  
curl -XGET '[http://localhost:9200/t/o/\_search?q=date:](http://localhost:9200/t/o/_search?q=date:)[2010-05-01 TO  
2010-05-03]'

I get this response:  
curl: (3) [globbing] error: bad range specification after pos 43

When I do this query:  
curl -XGET '[http://localhost:9200/t/o/\_search?q=date:](http://localhost:9200/t/o/_search?q=date:){2010-05-01 TO  
2010-05-03}'

I get this error (on the server):  
java.lang.IllegalArgumentException: invalid version format: TO  
2010-05-03 HTTP/1.1  
...

I thought that whatever I put the "q" parameter is passed to the  
Lucene query parser. So the queries I tried to run should work (see  
[http://lucene.apache.org/java/3\_0\_1/queryparsersyntax.html#Range%20Searches](http://lucene.apache.org/java/3_0_1/queryparsersyntax.html#Range%20Searches))

Seems like it fails way before it ever gets to the Lucene query  
parser.  
Any ideas how to solve this? (I'd rather not use DSL to do range  
queries)

---

<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: [April 27, 2010, 9:05pm UTC](https://discuss.elastic.co/t/date-range-query/2930/2 "2010-04-27T21:05:01Z")

</div>

Not sure how you tell curl to encode the url, but '[' needs to be encoded in  
this case. For example, here is how it should look like as an HTTP request:

GET /t/o/\_search?q=date:%5B2010-05-01%20TO%202010-05-03%5D HTTP/1.1

On Tue, Apr 27, 2010 at 11:00 PM, Tal [talsalmona@gmail.com](mailto:talsalmona@gmail.com) wrote:

> Hi,
> 
> I have an index that was created with the following calls:  
> curl -XPUT '[http://localhost:9200/t/o/1](http://localhost:9200/t/o/1)' -d '{name:"May 1st",  
> date:"2010-05-01"}'  
> curl -XPUT '[http://localhost:9200/t/o/2](http://localhost:9200/t/o/2)' -d '{name:"May 2nd",  
> date:"2010-05-02"}'  
> curl -XPUT '[http://localhost:9200/t/o/3](http://localhost:9200/t/o/3)' -d '{name:"May 3rd",  
> date:"2010-05-03"}'
> 
> The date field in the schema is correctly created and looks like this:  
> "date" : {  
> "type" : "date",  
> "index\_name" : "date",  
> "index" : "not\_analyzed",  
> "store" : "no",  
> "term\_vector" : "no",  
> "boost" : 1.0,  
> "omit\_norms" : true,  
> "omit\_term\_freq\_and\_positions" : true,  
> "precision\_step" : 4,  
> "format" : "dateOptionalTime"  
> }
> 
> When I do this query:  
> curl -XGET '[http://localhost:9200/t/o/\_search?q=date:2010-05-01](http://localhost:9200/t/o/_search?q=date:2010-05-01)'
> 
> I get the expected results:  
> {"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":  
> 1,"hits":[{"\_index":"t","\_type":"o","\_id":"1", "\_source" : {name:"May  
> 1st", date:"2010-05-01"}}]}}
> 
> When I do this query:  
> curl -XGET '[http://localhost:9200/t/o/\_search?q=date:](http://localhost:9200/t/o/_search?q=date:)[2010-05-01 TO  
> 2010-05-03]'
> 
> I get this response:  
> curl: (3) [globbing] error: bad range specification after pos 43
> 
> When I do this query:  
> curl -XGET '[http://localhost:9200/t/o/\_search?q=date:](http://localhost:9200/t/o/_search?q=date:){2010-05-01 TO  
> 2010-05-03}'
> 
> I get this error (on the server):  
> java.lang.IllegalArgumentException: invalid version format: TO  
> 2010-05-03 HTTP/1.1  
> ...
> 
> I thought that whatever I put the "q" parameter is passed to the  
> Lucene query parser. So the queries I tried to run should work (see  
> [Apache Lucene - Query Parser Syntax](http://lucene.apache.org/java/3_0_1/queryparsersyntax.html#Range%20Searches)  
> )
> 
> Seems like it fails way before it ever gets to the Lucene query  
> parser.  
> Any ideas how to solve this? (I'd rather not use DSL to do range  
> queries)

---

<div class="post-metadata">

### Author: ![talsalmona](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/talsalmona/32/3316_2.png) [@talsalmona](https://discuss.elastic.co/u/talsalmona)
#### Post date: [May 3, 2010, 8:08pm UTC](https://discuss.elastic.co/t/date-range-query/2930/3 "2010-05-03T20:08:42Z")

</div>

Right,  
I should have figured this out myself.

Thanks

On Apr 28, 12:05 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Not sure how you tell curl to encode the url, but '[' needs to be encoded in  
> this case. For example, here is how it should look like as an HTTP request:
> 
> GET /t/o/\_search?q=date:%5B2010-05-01%20TO%202010-05-03%5D HTTP/1.1
> 
> On Tue, Apr 27, 2010 at 11:00 PM, Tal [talsalm...@gmail.com](mailto:talsalm...@gmail.com) wrote:
> 
> > Hi,
> 
> > I have an index that was created with the following calls:  
> > curl -XPUT '[http://localhost:9200/t/o/1'-d](http://localhost:9200/t/o/1'-d) '{name:"May 1st",  
> > date:"2010-05-01"}'  
> > curl -XPUT '[http://localhost:9200/t/o/2'-d](http://localhost:9200/t/o/2'-d) '{name:"May 2nd",  
> > date:"2010-05-02"}'  
> > curl -XPUT '[http://localhost:9200/t/o/3'-d](http://localhost:9200/t/o/3'-d) '{name:"May 3rd",  
> > date:"2010-05-03"}'
> 
> > The date field in the schema is correctly created and looks like this:  
> > "date" : {  
> > "type" : "date",  
> > "index\_name" : "date",  
> > "index" : "not\_analyzed",  
> > "store" : "no",  
> > "term\_vector" : "no",  
> > "boost" : 1.0,  
> > "omit\_norms" : true,  
> > "omit\_term\_freq\_and\_positions" : true,  
> > "precision\_step" : 4,  
> > "format" : "dateOptionalTime"  
> > }
> 
> > When I do this query:  
> > curl -XGET '[http://localhost:9200/t/o/\_search?q=date:2010-05-01](http://localhost:9200/t/o/_search?q=date:2010-05-01)'
> 
> > I get the expected results:  
> > {"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":  
> > 1,"hits":[{"\_index":"t","\_type":"o","\_id":"1", "\_source" : {name:"May  
> > 1st", date:"2010-05-01"}}]}}
> 
> > When I do this query:  
> > curl -XGET '[http://localhost:9200/t/o/\_search?q=date:](http://localhost:9200/t/o/_search?q=date:)[2010-05-01 TO  
> > 2010-05-03]'
> 
> > I get this response:  
> > curl: (3) [globbing] error: bad range specification after pos 43
> 
> > When I do this query:  
> > curl -XGET '[http://localhost:9200/t/o/\_search?q=date:](http://localhost:9200/t/o/_search?q=date:){2010-05-01 TO  
> > 2010-05-03}'
> 
> > I get this error (on the server):  
> > java.lang.IllegalArgumentException: invalid version format: TO  
> > 2010-05-03 HTTP/1.1  
> > ...
> 
> > I thought that whatever I put the "q" parameter is passed to the  
> > Lucene query parser. So the queries I tried to run should work (see  
> > [Apache Lucene - Query Parser Syntax](http://lucene.apache.org/java/3_0_1/queryparsersyntax.html#Range%20Se)...  
> > )
> 
> > Seems like it fails way before it ever gets to the Lucene query  
> > parser.  
> > Any ideas how to solve this? (I'd rather not use DSL to do range  
> > queries)

---

<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:24am UTC](https://discuss.elastic.co/t/date-range-query/2930/4 "2017-07-06T04:24:18Z")

</div>


