Nested boolean range query returning values outside of its range

Hi -- I've been trying to get this query to work, and tried a filtered
query (as another post suggested), but I still have exactly the same
problem.
The current attempt looks like this:
{
"size": 18,
"sort": [
{
"listed_at": "desc"
}
],
"from": 0,
"query": {
"filtered": {
"filter": {
"and": [
{
"or": [
{
"range": {
"price": {
"to": 4.99,
"from": 0
}
}
}
]
}
]
},
"query": {
"term": {
"category_id": 1
}
}
}
}
}

Basically, I want to select all items under a given category_id, and filter
them on (potentially more than one) price range, as well as a number of
other terms filters (for things like colour_id, etc.).
Am I at least heading in sort-of the right direction with this approach?
Could anyone offer me any insight into what I'm missing about how this
works that makes me surprised that my efforts aren't returning what I
expect them to?
Thanks for any & all help,
Doug.

On 14 November 2011 19:49, doug livesey biot023@gmail.com wrote:

Hi, I have a bunch of records in an index called item, with varying prices.
I'm trying to construct a query that will allow me to retrieve items under
a particular category_id, and in one or more price ranges.
The query I've come up with is this:

{
"size": 18,
"sort": [
{
"listed_at": "desc"
}
],
"from": 0,
"query": {
"bool": {
"must": [
{
"term": {
"category_id": 1
}
},
{
"bool": {
"should": [
{
"range": {
"price": {
"to": 4.99,
"from": 0.0
}
}
}
]
}
}
]
}
}
}

I was hoping that it would return only items in the category_id 1, with a
price between 0.0 and 4.99 -- however, when I run it, I get only items in
category_id 1 well enough, but I also get all items under that
category_id, including those with a price of over 4.99.
Could someone advise me as to where I am going wrong?
Thankyou for any & all assistance.
Doug.