Hi Doug
On Tue, 2011-11-15 at 16:26 +0000, doug livesey wrote:
Damn' -- even this fails:
$ curl -XGET
"http://localhost:9200/folksy_test_search/items/_search?pretty=true"
-d
'{"size":18,"sort":[{"listed_at":"desc"}],"from":0,"query":{"filtered":{"filter":{"range":{"price":{"to":4.99,"from":0.0}}},"query":{"term":{"category_id":1}}}}}'
It is really much easier to help if these code examples are gisted and
formatted properly. There are just too many {{{{{}}}} to check
visually.
Also, if you create a complete example, you will probably find your
error.
I think that, if you check the mapping for 'item' you will find that the
'price' field is mapped as a string, so your "from" and "to" parameters
are being treated as strings, not as numbers.
When I try your example docs plus your example search, then it works for
me. If I change the mapping for "price" to "string", then I get all
results back.
You probably indexed a price as "0.50" early on, which messed up your
mapping.
good luck
clint
I've removed the "and" filter and just put the "range" filter in
directly, and still it returns items with a price outside the range.
On 15 November 2011 15:40, doug livesey biot023@gmail.com wrote:
Sorry -- just realised why you need the put requests, too --
having a long day, sorry!
Here they are:
curl -XPUT "http://localhost:9200/folksy_test_search/items/1"
-d
'{"price":10.0,"material_ids":[1],"listed_at":"20110915T152837","place_id":null,"title":"Red Jumper","section_id":1,"user_login":"user000001","id":1,"category_id":1,"colour_ids":[1],"description":"A beautiful red jumper hand-knitted with quality wool.","keywords":"Men Clothes Jumpers Blue Cotton","subcategory_id":1}'
curl -XPUT "http://localhost:9200/folksy_test_search/items/2"
-d
'{"price":10.0,"material_ids":[1],"listed_at":"20110915T152837","place_id":null,"title":"Red Jumper","section_id":1,"user_login":"user000003","id":2,"category_id":1,"colour_ids":[1],"description":"A beautiful red jumper hand-knitted with quality wool.","keywords":"Men Clothes Jumpers Blue Cotton","subcategory_id":1}'
curl -XPUT "http://localhost:9200/folksy_test_search/items/3"
-d
'{"price":3.0,"material_ids":[1],"listed_at":"20110915T152838","place_id":null,"title":"Red Jumper","section_id":1,"user_login":"user000005","id":3,"category_id":1,"colour_ids":[1],"description":"A beautiful red jumper hand-knitted with quality wool.","keywords":"Men Clothes Jumpers Blue Cotton","subcategory_id":1}'
curl -XPUT "http://localhost:9200/folksy_test_search/items/4"
-d
'{"price":3.0,"material_ids":[1],"listed_at":"20110915T152839","place_id":null,"title":"Red Jumper","section_id":1,"user_login":"user000007","id":4,"category_id":1,"colour_ids":[1],"description":"A beautiful red jumper hand-knitted with quality wool.","keywords":"Men Clothes Jumpers Blue Cotton","subcategory_id":1}'
Obviously, I only want the latter two items to appear in the
query.
Thanks again,
Doug.
On 15 November 2011 14:59, doug livesey <biot023@gmail.com>
wrote:
Hi, sure -- the indexing happens automatically to a
fresh index as part of testing -- the test process
automatically clears the index before tests commence.
The output of the search is
here: https://gist.github.com/1367263
This is for the second search, although it looks the
same for the first.
& thanks for looking at this.
On 15 November 2011 11:27, Shay Banon
<kimchy@gmail.com> wrote:
Both search requests look good. Can you gist a
simple recreation that shows this? A few curl
requests that index fresh data into a fresh
index, and the search request that shows wrong
results returning.
On Tue, Nov 15, 2011 at 1:12 PM, doug livesey
<biot023@gmail.com> wrote:
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.