2015-12-21 43 views
0

我試圖按字段順序排列元素,但不知道如何。這是我的代碼:在聚合中排序ES laravel

$laws_y = Law::searchByQuery([ 
    ], 
     [ 
      "group_by_law_year" => ["terms" => ['field' => "law_year", "size" => 100]] 
     ]); 

誰能幫助?

回答

0

您可以通過_term: desc使用order setting和秩序做到這一點:

$laws_y = Law::searchByQuery([ 
], 
[ 
    "group_by_law_year" => [ 
     "terms" => [ 
       'field' => "law_year", 
       "order" => ["_term" => "desc" ],  <--- add this line 
       "size" => 100 
     ] 
    ] 
]);