Elasticsearch嵌套聚合排序

时间:2015-06-17 12:30:06

标签: sorting elasticsearch nested

我希望按productId进行分组,并按navigations.sequence

对此产品进行排序

示例文档:

{   
    "productId": 2173253,
    "productIsActive": true,
    "sequence": 1070,
    "navigations": 
    [,
     {
       "id": 928,
       "sequence": 14940,
        "weekendSequence": 14865
        }
    ]
},
{

   "productId": 2171489,
   "sequence": 1070,
   "variantId":12
   "navigations": 
   [
     {
      "id": 928,
       "sequence": 46,
        "weekendSequence": 14865
     }
   ]
},
{
    "productId": 2158358,
    "sequence": 1070,
    "variantID":10
    "navigations":
     [
      {
       "id": 928,
       "sequence": 577,
       "weekendSequence": 14865
      }
    ]
},
{
   "productId": 2173253,
   "sequence": 1070,
   "variantID":1
   "navigations": 
    [
     {
      "id": 928,
      "sequence": 49,
      "weekendSequence": 14865
     }
    ]
}
 "Product": {
     "terms": {
        "field": "productId",
        "size": 10,
        "order":{"sorite":"desc"}
     },
     "aggs": {
        "tops": {
           "top_hits": {
              "size":56
           }
        },
        "sorite": {
           "nested": {
              "path": "navigations"
           },
           "aggs": {
              "ter": {
                 "filter": {
                    "term": {
                       "navigations.id": "928"
                   }
                 },
                 "sort":"asc",
                 "aggs": {
                    "son": {
                       "max": {
                          "field": "navigations.sequence"
                       }
                    }
                 } 
              }
           }
        }  
     }
  }

结果如下:

 {
    "key": 2173253,
    "doc_count": 24,
    "sorite": {
       "doc_count": 144,
       "ter": {
          "doc_count": 24,
          "son": {
             "value": 14940
          }
       }
    }
 },
 {
    "key": 2171489,
    "doc_count": 20,
    "sorite": {
       "doc_count": 80,
       "ter": {
          "doc_count": 20,
          "son": {
             "value": 46
          }
       }
    }
 },
 {
    "key": 2158358,
    "doc_count": 20,
    "sorite": {
       "doc_count": 64,
       "ter": {
          "doc_count": 20,
          "son": {
             "value": 577
          }
       }
    }
 }

我希望按“子”聚合结果排序聚合,但我无法使用它。 我不能在聚合过滤器和嵌套聚合中使用order关键字 如何按son聚合排序:value 49,577,14940

0 个答案:

没有答案