以下是官网手册(部分)(v5.1)

直接直接看官网手册

https://www.elastic.co/guide/en/elasticsearch/reference/5.1/search-aggregations-metrics-top-hits-aggregation.html

Top hits Aggregationedit

A top_hits metric aggregator keeps track of the most relevant document being aggregated. This aggregator is intended to be used as a sub aggregator, so that the top matching documents can be aggregated per bucket.

The top_hits aggregator can effectively be used to group result sets by certain fields via a bucket aggregator. One or more bucket aggregators determines by which properties a result set get sliced into.

Optionsedit

  • from - The offset from the first result you want to fetch.
  • size - The maximum number of top matching hits to return per bucket. By default the top three matching hits are returned.
  • sort - How the top matching hits should be sorted. By default the hits are sorted by the score of the main query.

Supported per hit featuresedit

The top_hits aggregation returns regular search hits, because of this many per hit features can be supported:

Exampleedit

In the following example we group the questions by tag and per tag we show the last active question. For each question only the title field is being included in the source.

{
"aggs": {
"top-tags": {
"terms": {
"field": "tags",
"size": 3
},
"aggs": {
"top_tag_hits": {
"top_hits": {
"sort": [
{
"last_activity_date": {
"order": "desc"
}
}
],
"_source": {
"includes": [
"title"
]
},
"size" : 1
}
}
}
}
}
}

Possible response snippet:

"aggregations": {
"top-tags": {
"buckets": [
{
"key": "windows-7",
"doc_count": 25365,
"top_tags_hits": {
"hits": {
"total": 25365,
"max_score": 1,
"hits": [
{
"_index": "stack",
"_type": "question",
"_id": "602679",
"_score": 1,
"_source": {
"title": "Windows port opening"
},
"sort": [
1370143231177
]
}
]
}
}
},
{
"key": "linux",
"doc_count": 18342,
"top_tags_hits": {
"hits": {
"total": 18342,
"max_score": 1,
"hits": [
{

最新文章

  1. [LeetCode] Product of Array Except Self 除本身之外的数组之积
  2. Linux学习心得之 Linux下ant安装与使用
  3. jQuery的document ready与 onload事件——你真的思考过吗?
  4. NBU AIX ORACLE10G RAC恢复到AIX单实例(表空间恢复)
  5. maven 创建Hadoop程序
  6. http://www.cnblogs.com/Matrix54/archive/2012/05/03/2481260.html
  7. linux 查找替换
  8. 百度面试题:从输入url到显示网页,后台发生了什么?
  9. 前端程序员:月薪 5K 到 5 万,我干了啥(转)
  10. memcached 使用积累
  11. 网络子系统41_inet_peer平衡二叉树的删除
  12. Ajenti 1.0 发布,服务器管理系统 - 开源中国社区
  13. Testin一日游实验室发布的行级APP质量报告:在那里拍携程双赢
  14. MyBatis 框架的搭建和配置
  15. HTML5入门(一)—— 基本标签&表格
  16. 剑指Offer——Java实现栈和队列的互模拟操作
  17. 20181117-python第二章学习小结-part1
  18. [Java] SpringMVC工作原理之一:DispatcherServlet
  19. scala-Unit-3-Scala基础语法2
  20. javascript监听数组变化

热门文章

  1. Spring框架入门之基于Java注解配置bean
  2. MSIL实用指南-加载和保存参数
  3. Oracle在VMware虚拟机安装的配置
  4. HTTP 8中请求方式介绍
  5. 在.net core web 项目中操作MySql数据库(非ORM框架,原生sql语句方式)
  6. JVM体系结构详解
  7. 使用Python爬取淘宝两千款套套
  8. Photoshop软件破解补丁安装方法
  9. hdu 1671 Phone List 字典树模板
  10. PHP 通过curl POST传递 伪造cookie 传递信息