<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>

                ## 聚合查詢 ### 簡介 聚合:**英文為Aggregation,是es除搜索功能外提供的針對es數據做統計分析的功能**。聚合有助于根據搜索查詢提供聚合數據。聚合查詢是數據庫中重要的功能特性,ES作為搜索引擎兼數據庫,同樣提供了強大的聚合分析能力。它基于查詢條件來對數據進行分桶、計算的方法。有點類似于 SQL 中的 group by 再加一些函數方法的操作。 > `注意事項:text類型是不支持聚合的。` ### 測試數據 ```json # 創建索引 index 和映射 mapping PUT /fruit { "mappings": { "properties": { "title":{ "type": "keyword" }, "price":{ "type":"double" }, "description":{ "type": "text", "analyzer": "ik_max_word" } } } } # 放入測試數據 PUT /fruit/_bulk {"index":{}} {"title" : "面包","price" : 19.9,"description" : "小面包非常好吃"} {"index":{}} {"title" : "旺仔牛奶","price" : 29.9,"description" : "非常好喝"} {"index":{}} {"title" : "日本豆","price" : 19.9,"description" : "日本豆非常好吃"} {"index":{}} {"title" : "小饅頭","price" : 19.9,"description" : "小饅頭非常好吃"} {"index":{}} {"title" : "大辣片","price" : 39.9,"description" : "大辣片非常好吃"} {"index":{}} {"title" : "透心涼","price" : 9.9,"description" : "透心涼非常好喝"} {"index":{}} {"title" : "小浣熊","price" : 19.9,"description" : "童年的味道"} {"index":{}} {"title" : "海苔","price" : 19.9,"description" : "海的味道"} ``` ### 使用 #### 根據某個字段分組 ```http # 根據某個字段進行分組 統計數量 GET /fruit/_search { "query": { "term": { "description": { "value": "好吃" } } }, "aggs": { "price_group": { "terms": { "field": "price" } } } } ``` #### 求最大值 ```http # 求最大值 GET /fruit/_search { "aggs": { "price_max": { "max": { "field": "price" } } } } ``` #### 求最小值 ```http # 求最小值 GET /fruit/_search { "aggs": { "price_min": { "min": { "field": "price" } } } } ``` #### 求平均值 ```http # 求平均值 GET /fruit/_search { "aggs": { "price_agv": { "avg": { "field": "price" } } } } ``` #### 求和 ```http # 求和 GET /fruit/_search { "aggs": { "price_sum": { "sum": { "field": "price" } } } } ```
                  <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>

                              哎呀哎呀视频在线观看