elasticsearch/elasticsearch — pull request #6151 by dadoonet (2014-05-13 13:57:18+00:00)
Title: Allow sorting on nested sub generated field (PR for 6150)

When you have a nested document and want to sort on its fields, it's perfectly doable on regular fields but not on "generated" sub fields.

Here is a SENSE recreation:

```
DELETE /tmp

PUT /tmp

PUT /tmp/doc/_mapping
{
"properties": {
"flat": {
"type": "string",
"index": "analyzed",
"fields": {
"sub": {
"type": "string",
"index": "not_analyzed"
}
}
},
"nested": {
"type": "nested",
"properties": {
"foo": {
"type": "string",
"index": "analyzed",
"fields": {
"sub": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}

PUT /tmp/doc/1
{
"flat":"bar",
"nested":{
"foo":"bar"
}
}
```

When sorting on `flat.sub` sub field, everything is fine:

```
GET /tmp/doc/_search
{
"sort": [
{
"flat.sub": {
"order": "desc"
}
}
]
}

# gives
# "sort": [
# "bar"
# ]
```

When sorting on `nested` field, everything is fine:

```
GET /tmp/doc/_search
{
"sort": [
{
"nested.foo": {
"order": "desc"
}
}
]
}

# gives
# "sort": [
# "bar"
# ]
```

But when sorting on `nested.sub` field, sorting is incorrect:

```
GET /tmp/doc/_search
{
"sort": [
{
"nested.foo.sub": {
"order": "desc"
}
}
]
}

# gives
# "sort": [
# null
# ]

Closes #6150.