# Nested sort and nested filter on v0.9

**URL:** <https://discuss.elastic.co/t/nested-sort-and-nested-filter-on-v0-9/12073>\
**Category:** Elasticsearch\
**Created:** [May 22, 2013, 12:50pm UTC](https://discuss.elastic.co/t/nested-sort-and-nested-filter-on-v0-9/12073 "2013-05-22T12:50:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![garnaes](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@garnaes](https://discuss.elastic.co/u/garnaes)\
**Post date:** [May 22, 2013, 12:50pm UTC](https://discuss.elastic.co/t/nested-sort-and-nested-filter-on-v0-9/12073/1 "2013-05-22T12:50:27Z")

</div>

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](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](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](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](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [May 23, 2013, 8:47am UTC](https://discuss.elastic.co/t/nested-sort-and-nested-filter-on-v0-9/12073/2 "2013-05-23T08:47:30Z")

</div>

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](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![garnaes](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@garnaes](https://discuss.elastic.co/u/garnaes)\
**Post date:** [May 23, 2013, 9:13am UTC](https://discuss.elastic.co/t/nested-sort-and-nested-filter-on-v0-9/12073/3 "2013-05-23T09:13:28Z")

</div>

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](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:35am UTC](https://discuss.elastic.co/t/nested-sort-and-nested-filter-on-v0-9/12073/4 "2017-07-06T02:35:13Z")

</div>


