<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 執行聚合 聚合提供了分組并統計數據的能力。理解聚合的最簡單的方式是將其粗略地等同為SQL的GROUP BY和SQL聚合函數。在Elasticsearch中,你可以在一個響應中同時返回命中的數據和聚合結果。你可以使用簡單的API同時運行查詢和多個聚合并一次返回,這避免了來回的網絡通信,是非常強大和高效的。 首先,這個例子演示了根據賬戶所在的州來統計各個州的賬戶數,并返回賬戶數最多的前10個州(默認大小為10): ``` GET /bank/_search { "size": 0, "aggs": { "group_by_state": { "terms": { "field": "state.keyword" } } } } ``` 在SQL中,上面的聚合在概念上類似于: ``` SELECT COUNT(*) from bank GROUP BY state ORDER BY COUNT(*) DESC ``` 響應(其中一部分)是: ``` { "took": 29, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits" : { "total" : 1000, "max_score" : 0.0, "hits" : [ ] }, "aggregations" : { "group_by_state" : { "doc_count_error_upper_bound": 20, "sum_other_doc_count": 770, "buckets" : [ { "key" : "ID", "doc_count" : 27 }, { "key" : "TX", "doc_count" : 27 }, { "key" : "AL", "doc_count" : 25 }, { "key" : "MD", "doc_count" : 25 }, { "key" : "TN", "doc_count" : 23 }, { "key" : "MA", "doc_count" : 21 }, { "key" : "NC", "doc_count" : 21 }, { "key" : "ND", "doc_count" : 21 }, { "key" : "ME", "doc_count" : 20 }, { "key" : "MO", "doc_count" : 20 } ] } } } ``` 我們可以看到`ID`(Idaho)州有27個賬戶,緊跟著`TX`(Texas)州有27個賬戶、`AL`(Alabama)有25個賬戶,依此類推。 注意我們將`size`設置成 0,這樣我們就可以只看到聚合結果了,而不會顯示命中的文檔的詳細結果。 在先前聚合的基礎上,現在這個例子計算了每個州的賬戶的平均存款(還是按照賬戶數量倒序排序的前10個州): ``` GET /bank/_search { "size": 0, "aggs": { "group_by_state": { "terms": { "field": "state.keyword" }, "aggs": { "average_balance": { "avg": { "field": "balance" } } } } } } ``` 注意, 我們把`average_balance`聚合嵌套在了`group_by_state`聚合之中。這是所有聚合的一個常用模式。你可以在任意的聚合之中嵌套聚合,這樣就可以從你的數據中抽取出想要的結果。 在前面的聚合的基礎上,現在讓我們按照平均余額進行排序: ``` GET /bank/_search { "size": 0, "aggs": { "group_by_state": { "terms": { "field": "state.keyword", "order": { "average_balance": "desc" } }, "aggs": { "average_balance": { "avg": { "field": "balance" } } } } } } ``` 下面的例子顯示了如何使用年齡段(20-29,30-39,40-49)分組,然后再用性別分組,最后為每一個年齡段的每組性別計算平均賬戶余額。 ``` GET /bank/_search { "size": 0, "aggs": { "group_by_age": { "range": { "field": "age", "ranges": [ { "from": 20, "to": 30 }, { "from": 30, "to": 40 }, { "from": 40, "to": 50 } ] }, "aggs": { "group_by_gender": { "terms": { "field": "gender.keyword" }, "aggs": { "average_balance": { "avg": { "field": "balance" } } } } } } } } ``` There are many other aggregations capabilities that we won’t go into detail here. The [aggregations reference guide](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/search-aggregations.html) is a great starting point if you want to do further experimentation.
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看