zoukankan      html  css  js  c++  java
  • 读《深入理解Elasticsearch》点滴-聚合-top_hits

    以下是官网手册(部分)(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": [
                        {
  • 相关阅读:
    MySQL 联合索引测试
    Redis的安装
    MySQL中int(5) 中的5代表什么意思?
    JS树结构转list结构
    SpringMVC数组参数
    立即执行函数(function(){})()与闭包
    女票口红礼物列表
    Idea中编辑后需要重启问题
    Myeclipse6.5迁移到IDEA
    Layui前端框架
  • 原文地址:https://www.cnblogs.com/jiangtao1218/p/8595059.html
Copyright © 2011-2022 走看看