Numeric Range Query

Hi,

I'd like to do combined range query on document like

document {
start: 10,
stop: 20
}

Querying using '{ query : { range : {start: { from :null, to:
15 } } }' works fine,
but how to do something like :

'{ query : { range : {start: { from :null, to: 15 } }, stop: { from:
15, to: null} }'

I tried to combine them using boolean query without success.

Any clue ?

Thank you

Your thoughts are correct, you should use a boolean query with (I am
guessing) two must clauses which will return an AND basically of the two
clauses, here is an example:

{
bool : {
must : {
range : { ... }
},
must: {
range : { ... }
}
}
}

-shay.banon

On Thu, Feb 11, 2010 at 4:54 PM, Rabbit antonin.bonte@gmail.com wrote:

Hi,

I'd like to do combined range query on document like

document {
start: 10,
stop: 20
}

Querying using '{ query : { range : {start: { from :null, to:
15 } } }' works fine,
but how to do something like :

'{ query : { range : {start: { from :null, to: 15 } }, stop: { from:
15, to: null} }'

I tried to combine them using boolean query without success.

Any clue ?

Thank you

curl -X GET "http://localhost:9200/ip/_search?pretty=true" -d
\ (~/workspace/
RestServer/dat)
'{
bool : {
must : {
range : { start: { from :null, to: 15 } }
},
must: {
range : { stop: { from :15, to: null } }
}
}
}'
{
"_shards" : {
"total" : 5,
"successful" : 0,
"failed" : 5
},
"hits" : {
"total" : 0,
"hits" :
}
}%

do not return any result.

match_all returns :

"hits" : {
"total" : 2,
"hits" : [ {
"_index" : "ip",
"_type" : "range",
"_id" : "1", "_source" : {
start: 1511729664,
stop: 1511729919,
location: 210743
}

}, {
  "_index" : "ip",
  "_type" : "range",
  "_id" : "2", "_source" : {
    start: 10,
    stop: 20,
    location: 210743

}

I must be omitting something obvious :slight_smile:

On Feb 11, 4:00 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Your thoughts are correct, you should use a boolean query with (I am
guessing) two must clauses which will return an AND basically of the two
clauses, here is an example:

{
bool : {
must : {
range : { ... }
},
must: {
range : { ... }
}
}

}

-shay.banon

On Thu, Feb 11, 2010 at 4:54 PM, Rabbit antonin.bo...@gmail.com wrote:

Hi,

I'd like to do combined range query on document like

document {
start: 10,
stop: 20
}

Querying using '{ query : { range : {start: { from :null, to:
15 } } }' works fine,
but how to do something like :

'{ query : { range : {start: { from :null, to: 15 } }, stop: { from:
15, to: null} }'

I tried to combine them using boolean query without success.

Any clue ?

Thank you

Yep, the actual Json should include the query tag as explained here:
http://www.elasticsearch.com/docs/elasticsearch/json_api/search/. In your
case:

{
query : {
bool : {
must : {
range : { start: { from :null, to: 15 } }
},
must: {
range : { stop: { from :15, to: null } }
}
}
}
}

The reason why its wrapped in query is because there are other parameters
that you can pass on the search request JSON.

-shay.banon

On Thu, Feb 11, 2010 at 5:17 PM, Rabbit antonin.bonte@gmail.com wrote:

curl -X GET "http://localhost:9200/ip/_search?pretty=true" -d
\ (~/workspace/
RestServer/dat)
'{
bool : {
must : {
range : { start: { from :null, to: 15 } }
},
must: {
range : { stop: { from :15, to: null } }
}
}
}'
{
"_shards" : {
"total" : 5,
"successful" : 0,
"failed" : 5
},
"hits" : {
"total" : 0,
"hits" :
}
}%

do not return any result.

match_all returns :

"hits" : {
"total" : 2,
"hits" : [ {
"_index" : "ip",
"_type" : "range",
"_id" : "1", "_source" : {
start: 1511729664,
stop: 1511729919,
location: 210743
}

}, {
"_index" : "ip",
"_type" : "range",
"_id" : "2", "_source" : {
start: 10,
stop: 20,
location: 210743
}

I must be omitting something obvious :slight_smile:

On Feb 11, 4:00 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Your thoughts are correct, you should use a boolean query with (I am
guessing) two must clauses which will return an AND basically of the two
clauses, here is an example:

{
bool : {
must : {
range : { ... }
},
must: {
range : { ... }
}
}

}

-shay.banon

On Thu, Feb 11, 2010 at 4:54 PM, Rabbit antonin.bo...@gmail.com wrote:

Hi,

I'd like to do combined range query on document like

document {
start: 10,
stop: 20
}

Querying using '{ query : { range : {start: { from :null, to:
15 } } }' works fine,
but how to do something like :

'{ query : { range : {start: { from :null, to: 15 } }, stop: { from:
15, to: null} }'

I tried to combine them using boolean query without success.

Any clue ?

Thank you

thank you, works fine now

On Feb 11, 4:21 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Yep, the actual Json should include the query tag as explained here:http://www.elasticsearch.com/docs/elasticsearch/json_api/search/. In your
case:

{
query : {
bool : {
must : {
range : { start: { from :null, to: 15 } }
},
must: {
range : { stop: { from :15, to: null } }
}
}
}

}

The reason why its wrapped in query is because there are other parameters
that you can pass on the search request JSON.

-shay.banon

On Thu, Feb 11, 2010 at 5:17 PM, Rabbit antonin.bo...@gmail.com wrote:

curl -X GET "http://localhost:9200/ip/_search?pretty=true" -d
\ (~/workspace/
RestServer/dat)
'{
bool : {
must : {
range : { start: { from :null, to: 15 } }
},
must: {
range : { stop: { from :15, to: null } }
}
}
}'
{
"_shards" : {
"total" : 5,
"successful" : 0,
"failed" : 5
},
"hits" : {
"total" : 0,
"hits" :
}
}%

do not return any result.

match_all returns :

"hits" : {
"total" : 2,
"hits" : [ {
"_index" : "ip",
"_type" : "range",
"_id" : "1", "_source" : {
start: 1511729664,
stop: 1511729919,
location: 210743
}

}, {
"_index" : "ip",
"_type" : "range",
"_id" : "2", "_source" : {
start: 10,
stop: 20,
location: 210743
}

I must be omitting something obvious :slight_smile:

On Feb 11, 4:00 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Your thoughts are correct, you should use a boolean query with (I am
guessing) two must clauses which will return an AND basically of the two
clauses, here is an example:

{
bool : {
must : {
range : { ... }
},
must: {
range : { ... }
}
}

}

-shay.banon

On Thu, Feb 11, 2010 at 4:54 PM, Rabbit antonin.bo...@gmail.com wrote:

Hi,

I'd like to do combined range query on document like

document {
start: 10,
stop: 20
}

Querying using '{ query : { range : {start: { from :null, to:
15 } } }' works fine,
but how to do something like :

'{ query : { range : {start: { from :null, to: 15 } }, stop: { from:
15, to: null} }'

I tried to combine them using boolean query without success.

Any clue ?

Thank you

Great!, would love to hear your experiance with elasticsearch once you
get enough milage on it :wink:

-shay.banon

On 2/11/10, Rabbit antonin.bonte@gmail.com wrote:

thank you, works fine now

On Feb 11, 4:21 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Yep, the actual Json should include the query tag as explained
here:http://www.elasticsearch.com/docs/elasticsearch/json_api/search/. In
your
case:

{
query : {
bool : {
must : {
range : { start: { from :null, to: 15 } }
},
must: {
range : { stop: { from :15, to: null } }
}
}
}

}

The reason why its wrapped in query is because there are other parameters
that you can pass on the search request JSON.

-shay.banon

On Thu, Feb 11, 2010 at 5:17 PM, Rabbit antonin.bo...@gmail.com wrote:

curl -X GET "http://localhost:9200/ip/_search?pretty=true" -d
\ (~/workspace/
RestServer/dat)
'{
bool : {
must : {
range : { start: { from :null, to: 15 } }
},
must: {
range : { stop: { from :15, to: null } }
}
}
}'
{
"_shards" : {
"total" : 5,
"successful" : 0,
"failed" : 5
},
"hits" : {
"total" : 0,
"hits" :
}
}%

do not return any result.

match_all returns :

"hits" : {
"total" : 2,
"hits" : [ {
"_index" : "ip",
"_type" : "range",
"_id" : "1", "_source" : {
start: 1511729664,
stop: 1511729919,
location: 210743
}

}, {
"_index" : "ip",
"_type" : "range",
"_id" : "2", "_source" : {
start: 10,
stop: 20,
location: 210743
}

I must be omitting something obvious :slight_smile:

On Feb 11, 4:00 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Your thoughts are correct, you should use a boolean query with (I am
guessing) two must clauses which will return an AND basically of the
two
clauses, here is an example:

{
bool : {
must : {
range : { ... }
},
must: {
range : { ... }
}
}

}

-shay.banon

On Thu, Feb 11, 2010 at 4:54 PM, Rabbit antonin.bo...@gmail.com
wrote:

Hi,

I'd like to do combined range query on document like

document {
start: 10,
stop: 20
}

Querying using '{ query : { range : {start: { from :null, to:
15 } } }' works fine,
but how to do something like :

'{ query : { range : {start: { from :null, to: 15 } }, stop: { from:
15, to: null} }'

I tried to combine them using boolean query without success.

Any clue ?

Thank you

--
Sent from my mobile device

On Feb 11, 3:00 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Your thoughts are correct, you should use a boolean query with (I am
guessing) two must clauses which will return an AND basically of the two
clauses, here is an example:

{
bool : {
must : {
range : { ... }
},
must: {
range : { ... }
}
}
}

I'm a bit worried about that example - it isn't valid JSON according
to the JSON spec (which requires double quotes around all strings),
but more importantly JSON objects shouldn't have two keys with the
same names. If you feed the above in to many (most?) JSON libraries
you'll lose data. Here's what the Python JSON library does with it,
for example:

In [45]: s = """{
....: "bool" : {
....: "must" : {
....: "range" : 1
....: },
....: "must": {
....: "range" : 2
....: }
....: }
....: }"""

In [46]: json.loads(s)
Out[46]: {u'bool': {u'must': {u'range': 2}}}

One fix would be to use the following syntax instead:

{
"bool" : {
"must" : [
{
"range" : { ... }
},
{
"range": { ... }
}
]
}
}

You are absolutely right, it format supported should be supported as
well.Though I think the current format is a valid JSON, I think there is the
underlying assumption that field names should be unique. So, I created the
following issue:
Issues · elastic/elasticsearch · GitHub and it should
be fixed by now in master :slight_smile:

-shay.banon

On Fri, Feb 12, 2010 at 2:34 PM, Simon Willison simon@simonwillison.netwrote:

On Feb 11, 3:00 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Your thoughts are correct, you should use a boolean query with (I am
guessing) two must clauses which will return an AND basically of the two
clauses, here is an example:

{
bool : {
must : {
range : { ... }
},
must: {
range : { ... }
}
}
}

I'm a bit worried about that example - it isn't valid JSON according
to the JSON spec (which requires double quotes around all strings),
but more importantly JSON objects shouldn't have two keys with the
same names. If you feed the above in to many (most?) JSON libraries
you'll lose data. Here's what the Python JSON library does with it,
for example:

In [45]: s = """{
....: "bool" : {
....: "must" : {
....: "range" : 1
....: },
....: "must": {
....: "range" : 2
....: }
....: }
....: }"""

In [46]: json.loads(s)
Out[46]: {u'bool': {u'must': {u'range': 2}}}

One fix would be to use the following syntax instead:

{
"bool" : {
"must" : [
{
"range" : { ... }
},
{
"range": { ... }
}
]
}
}