Sort on a deeply nested field?

Hi folks. Can you sort on a deeply nested field? I ask because this query:

curl -X GET 'localhost:9200/test/product/_search?pretty=true' -d '{
"sort" : [{ "items.properties.color.orig": {"order": "asc"} }]
}'

fails with this:

QueryPhaseExecutionException[[test][2]:
query[ConstantScore(:)],from[0],size[10],sort[<custom:"items.properties.color.orig":
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@f590c6>]:
Query Failed [Failed to execute main query]]; nested: IOException[Can't
sort on string types with more than one value per doc, or more than one
token per field];

However, as far as I can tell, the mapping does in fact contain
"items.properties.color.orig", which is an unanalyzed string:

Any idea what I'm doing wrong?

Yes, you can sort on "deeply nested field" (and you don't need to add
properties to get there, i.e. it can be obj1.obj2.field3), but you can't
sort on a field with multiple values.

On Fri, Nov 18, 2011 at 9:40 AM, Nick Hoffman nick@deadorange.com wrote:

Hi folks. Can you sort on a deeply nested field? I ask because this query:

curl -X GET 'localhost:9200/test/product/_search?pretty=true' -d '{
"sort" : [{ "items.properties.color.orig": {"order": "asc"} }]
}'

fails with this:

QueryPhaseExecutionException[[test][2]:
query[ConstantScore(:)],from[0],size[10],sort[<custom:"items.properties.color.orig":
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@f590c6>]:
Query Failed [Failed to execute main query]]; nested: IOException[Can't
sort on string types with more than one value per doc, or more than one
token per field];

However, as far as I can tell, the mapping does in fact contain
"items.properties.color.orig", which is an unanalyzed string:
Why does sorting fail here? · GitHub

Any idea what I'm doing wrong?

The "properties" is a keyword that's used in my app and that we decided to
use in ES, too.

Any idea why the error in that gist is occurring? I've been wracking brain,
but can't see anything wrong with the mapping, document, or query.

On IRC, kimchy identified what the problem is. The document that I've
indexed:

{
"name" : "Snoprinsessa Barbie",
"items" : [
{ "name" : "Faux fur-trimmed parka", "properties" : {"color" : "White"}
},
{ "name" : "Stud Diamond Ring", "properties" : {"color" : "Clear"} }
]
}

has an array of strings, which obviously can't be sorted. I didn't realize
that the "items" field being an array was a problem.

bitsweat_ suggested I look at parent-child support: