Equivalent to sort by "mode and nested filter" in aggs and query


I have this mapping example:

   "exampleobject": {
      "properties": {
         "name": {"type":"string"},
         "comments": {
               "properties": {               
                  "comment": {"type":"string"},
                  "value": {"type":"integer"}

I can sort my exampleobjects by the sum of its nested field "comments.value", but only the values of the comments who match a query in nested field "comments.comment":

'sort': {
    'comments.value': {
        'mode': 'sum',
        'order': 'desc',
        'nested_filter': {
            'query': {'match' :{'comments.comment': 'XXXXXX'}}

With this sorting, elastic filters the nested object "comments" by the query, then sums their value by exampleobject and finally orders the exampleobjects by its sum.

This works ok, but I need to aggregate and query too in this way and I dont know how to do it. There is an equivalent of the "mode and nested filter" in ES 1.7 in aggregations and queries?

I would like to have a range aggregation (or an histogram) of these nested sums filtered by a query. For example, I would like a response like this:

"aggregations": {
    "sumofvalue_filteredby_commentXXXX" : {
        "buckets": [
            { "to": 50, "doc_count": 400},
            { "from": 50, "to": 100, "doc_count": 200},
            { "from": 100, "doc_count": 100}

And of course, I need to query my exampleobjects with a range query of these nested and filtered sums. For example, retrieve only the exampleobjects of the bucket from:50 to:100

Do you know how to do it?

Thanks a lot,