# Sorting on nested elements

**URL:** <https://discuss.elastic.co/t/sorting-on-nested-elements/23580>\
**Category:** Elasticsearch\
**Created:** [May 6, 2015, 7:06pm UTC](https://discuss.elastic.co/t/sorting-on-nested-elements/23580 "2015-05-06T19:06:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blake\_McBride](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@Blake\_McBride](https://discuss.elastic.co/u/Blake_McBride)\
**Post date:** [May 6, 2015, 7:06pm UTC](https://discuss.elastic.co/t/sorting-on-nested-elements/23580/1 "2015-05-06T19:06:15Z")

</div>

I have a query that I want to be sorted by specific nested elements. I get  
back the correct result with no errors, but it is not sorted. I feel  
confident that it is something to do with the "sort" element of my query.  
Really kind of lost. Sure appreciate some help.

Mapping:

{  
"components": {  
mappings: {  
component: {  
properties: {  
classifications: { type: "string", index: "not\_analyzed" },  
componentProperties: {  
type: "nested",  
properties: {  
name: { type: "string" },  
numericValue: { type: "double" },  
stringValue: { type: "string" },  
units: { type: "string" }  
}  
},  
name: { type: "string" },  
position: { type: "long" }  
}  
}  
}  
}  
}

Query:

curl -s -XGET '[http://localhost:9200/components/\_search](http://localhost:9200/components/_search)' -d '{  
from: 0,  
size: 20,  
query: {  
bool: {  
must: [  
{  
match\_phrase\_prefix: { classifications:  
"passive\_components/resistors/single\_components/" }  
}  
]  
}  
},  
sort: [  
{  
"componentProperties.numericValue": {  
order: "asc",  
nested\_filter: { term: { "componentProperties.name": "Resistance" }  
}  
}  
}  
]  
}  
'

So, I want it sorted by the numericValue element when that element is  
associated with name=Resistance.

Example single document:

```
  {
    _index: "components",
    _type: "component",
    _id: "391a635c-ee56-46d1-9d9e-343d89b323c5",
    _score: null,
    _source: {
      name: "R 1206 1.1 0.333W 5% Thick Film",
      classifications: 

```

"passive\_components/resistors/single\_components/",  
componentProperties: [  
{  
name: "Resistance",  
stringValue: "1.1",  
numericValue: 1.1,  
units: "ohm"  
},  
{  
name: "Cp",  
stringValue: "0.07e-12",  
numericValue: 7e-14,  
units: "F"  
},  
{ name: "Octopart mpn", stringValue: "ESR18EZPJ1R1" },  
{  
name: "Ls",  
stringValue: "0.95e-9",  
numericValue: 9.5e-10,  
units: "H"  
}  
],  
position: 12  
},  
sort: ["Infinity"]  
}

Sure appreciate some help!

Thanks.

Blake McBride

## -- Please update your bookmarks! We moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)

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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9b327396-c525-4aef-95bc-ace863593046%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9b327396-c525-4aef-95bc-ace863593046%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:15am UTC](https://discuss.elastic.co/t/sorting-on-nested-elements/23580/2 "2017-07-06T00:15:20Z")

</div>


