garnaes
(garnaes)
May 22, 2013, 12:50pm
1
I'm having some difficulties with nested sort and nested filter, which I
thought ElasticSearch v0.9 supported. I have some documents that are rated
per user, and would like to get results sorted by the users ratings. The
following commands show my intent:
curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1 ' -d '
{
"mappings" : {
"movies" : {
"properties" : {
"ratings" : {
"type" : "nested"
}
}
}
}
}
'
curl -XPOST 'http://127.0.0.1:9200/test/movies?pretty=1 ' -d '
{
"title": "Spiderman",
"ratings" : [
{
"user_id" : 1,
"rating" : 5
},
{
"user_id" : 2,
"rating" : 3
}
]
}
'
curl -XPOST 'http://127.0.0.1:9200/test/movies?pretty=1 ' -d '
{
"title": "Titanic",
"ratings" : [
{
"user_id" : 1,
"rating" : 2
},
{
"user_id" : 2,
"rating" : 4
}
]
}
'
curl -XGET 'http://127.0.0.1:9200/test/movies/_search?pretty=1 ' -d '
{
"sort" : [
{
"ratings.rating" : {
"sort_order" : "desc",
"sort_mode" : "max",
"nested_filter": {
"term": {
"ratings.user_id": 2
}
}
}
}
]
}
'
I was expecting the last query to return Titanic first and Spiderman
second, but that's not the case. Am I doing something wrong, or is this
simply not supported?
Thanks in advance,
Andreas
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com .
For more options, visit https://groups.google.com/groups/opt_out .
Hiya
I was expecting the last query to return Titanic first and Spiderman
second, but that's not the case. Am I doing something wrong, or is this
simply not supported?
You're almost there. Just the names of some parameters are incorrect. Try
this:
curl -XGET 'http://127.0.0.1:9200/test/_search?pretty=1 ' -d '
{
"sort" : {
"ratings.rating" : {
"nested_filter" : {
"term" : {
"ratings.user_id" : 2
}
},
"mode" : "max",
"order" : "desc"
}
}
}
'
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com .
For more options, visit https://groups.google.com/groups/opt_out .
garnaes
(garnaes)
May 23, 2013, 9:13am
3
Works perfectly! Thanks a lot, Clinton.
On Thursday, 23 May 2013 10:47:30 UTC+2, Clinton Gormley wrote:
Hiya
I was expecting the last query to return Titanic first and Spiderman
second, but that's not the case. Am I doing something wrong, or is this
simply not supported?
You're almost there. Just the names of some parameters are incorrect.
Try this:
curl -XGET 'http://127.0.0.1:9200/test/_search?pretty=1 ' -d '
{
"sort" : {
"ratings.rating" : {
"nested_filter" : {
"term" : {
"ratings.user_id" : 2
}
},
"mode" : "max",
"order" : "desc"
}
}
}
'
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com .
For more options, visit https://groups.google.com/groups/opt_out .