Date range query


(talsalmona) #1

Hi,

I have an index that was created with the following calls:
curl -XPUT 'http://localhost:9200/t/o/1' -d '{name:"May 1st",
date:"2010-05-01"}'
curl -XPUT 'http://localhost:9200/t/o/2' -d '{name:"May 2nd",
date:"2010-05-02"}'
curl -XPUT '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'

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:[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:{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)

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)


(Shay Banon) #2

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 wrote:

Hi,

I have an index that was created with the following calls:
curl -XPUT 'http://localhost:9200/t/o/1' -d '{name:"May 1st",
date:"2010-05-01"}'
curl -XPUT 'http://localhost:9200/t/o/2' -d '{name:"May 2nd",
date:"2010-05-02"}'
curl -XPUT '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'

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:[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:{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
)

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)


(talsalmona) #3

Right,
I should have figured this out myself.

Thanks

On Apr 28, 12:05 am, Shay Banon 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 wrote:

Hi,

I have an index that was created with the following calls:
curl -XPUT 'http://localhost:9200/t/o/1'-d '{name:"May 1st",
date:"2010-05-01"}'
curl -XPUT 'http://localhost:9200/t/o/2'-d '{name:"May 2nd",
date:"2010-05-02"}'
curl -XPUT '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'

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:[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:{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%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)


(system) #4