Sort not working with nested query in elasticsearch

I have been working on the nested query, and i need to sort the results,
but as explained at
http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html there
is not dattribute for the sort, but i tried it at query level, even script
is not working inside nested query, can anyone please give me the
solution?? the data is as follows:

{
"query": {
"nested": {
"path": "guids_rated_fan_inverse",
"query": {
"term": {
"guids_rated_fan_inverse.guid": "34"
}
},
"sort": {
"guids_rated_fan_inverse.time_created": {
"order": "desc"
}
}
}
}
}

Data is::

guids_rated_fan_inverse: [

  • {
    • guid: 34
    • time_created: 1320479261
      }
  • {
    • guid: 600
    • time_created: 1320479635
      }

]

Thanks...

Hi Narinder

On Sun, 2011-11-06 at 21:11 -0800, Narinder Kaur wrote:

I have been working on the nested query, and i need to sort the
results, but as explained at
Elasticsearch Platform — Find real-time answers at scale | Elastic there is not dattribute for the sort, but i tried it at query level, even script is not working inside nested query, can anyone please give me the solution?? the data is as follows:

Two problems here:

  1. The data from nested objects is only available outside a nested query
    if you have set include_in_parent or include_in_root

  2. If you do the above, then the parent object will have multiple
    values for guids_rated_fan_inverse.time_created and you can't
    sort on multi-value fields

clint

{
"query": {
"nested": {
"path": "guids_rated_fan_inverse",
"query": {
"term": {
"guids_rated_fan_inverse.guid": "34"
}
},
"sort": {
"guids_rated_fan_inverse.time_created": {
"order": "desc"
}
}
}
}
}

Data is::

guids_rated_fan_inverse: [
* {
* guid: 34
* time_created: 1320479261
}
* {
* guid: 600
* time_created: 1320479635
}
]

Thanks...

No I have not set any of the two parameters include_in_parent or
include_in_root.

Rather I should say that sort is not working in nested query, here in the
following example, the title is not the attribute of the nested structure,
but sort is not working on title even.
{
"query": {
"nested": {
"path": "guids_rated_fan_inverse",
"query": {
"term": {
"guids_rated_fan_inverse.guid": "34"
}
},
"sort": {
"title": {
"order": "desc"
}
}
}
}
}
and the structure of the document is :

title: "abc",
guids_rated_fan_inverse: [

  • {
    • guid: 34
    • time_created: 1320479261
      }
  • {
    • guid: 600
    • time_created: 1320479635
      }

]