この例だと13行目でorderにtop_hitを指定して、downlaod_count(数値のmax)でソートしてるけど、title.raw(※やりたかったのはgroup_name.rawでした)のようにタイトル(文字列)順でソートしたい...。例では、gidでグルーピングし、グループ毎に新しい順(released_at)で上位1件取得。
Last active
August 29, 2015 14:04
-
-
Save shoito/7bd8800d40d3a5b3da13 to your computer and use it in GitHub Desktop.
ElasticsearchでField Collapsing/Combining http://qiita.com/shoito/items/e56aba6c76f27e16167b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"size": 0, | |
"query": { | |
"match": { | |
"title": "ほげ" | |
} | |
}, | |
"aggs": { | |
"hits": { | |
"terms": { | |
"field": "gid", | |
"order": { | |
"top_hit": "desc" | |
} | |
}, | |
"aggs": { | |
"top": { | |
"top_hits": { | |
"sort": [ | |
{ | |
"released_at": { | |
"order": "desc" | |
} | |
} | |
], | |
"size": 1 | |
} | |
}, | |
"top_hit": { | |
"max": { | |
"field": "downlaod_count" | |
} | |
} | |
} | |
} | |
} | |
} |
おぉー、ありがとうございます。
確かに事前にソート兼aggs用のフィールドを作っておくのがベターな気がしますね。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
事前にソート用かaggs用にそのデータを入れておくと幸せかもですね。
良さそうな手を思いつかなくて。。。