美文网首页
4.1 指标聚合 ★★★

4.1 指标聚合 ★★★

作者: 秦汉邮侠 | 来源:发表于2020-05-28 22:39 被阅读0次

    示例

    DELETE recipes
    
    PUT recipes
    
    POST /recipes/_mapping
    {
      "properties": {
        "name":{
          "type": "text"
        },
        "rating":{
          "type": "float"
        },"type":{
          "type": "keyword"
        }
      }
    }
    
    POST _bulk
    { "index":  { "_index": "recipes" }}
    {"name":"清蒸鱼头","rating":1,"type":"湘菜"}
    { "index":  { "_index": "recipes" }} 
    {"name":"剁椒鱼头","rating":2,"type":"湘菜"}
    { "index":  { "_index": "recipes" }} 
    {"name":"红烧鲫鱼","rating":3,"type":"湘菜"}
    { "index":  { "_index": "recipes" }} 
    {"name":"鲫鱼汤(辣)","rating":3,"type":"湘菜"}
    { "index":  { "_index": "recipes" }} 
    {"name":"鲫鱼汤(微辣)","rating":4,"type":"湘菜"}
    { "index":  { "_index": "recipes" }} 
    {"name":"鲫鱼汤(变态辣)","rating":5,"type":"湘菜"}
    { "index":  { "_index": "recipes" }} 
    {"name":"广式鲫鱼汤","rating":5,"type":"粤菜"}
    { "index":  { "_index": "recipes" }} 
    {"name":"鱼香肉丝","rating":2,"type":"川菜"}
    { "index":  { "_index": "recipes" }} 
    {"name":"奶油鲍鱼汤","rating":2,"type":"西菜"}
    
    
    POST recipes/_search
    {
      "query": {"match": {
        "name": "鱼"
      }},"size": 10
    }
    
    POST recipes/_search
    {
        "query": {
            "match": {
                "name": "鲫鱼"
            }
        },
        "sort": [{
            "rating": {
                "order": "desc"
            }
        }],
        "size": 10
    }
    
    POST recipes/_search
    {
        "query": {
            "match": {
                "name": "鱼"
            }
        },
        "sort": [{
            "rating": {
                "order": "desc"
            }
        }],
        "size": 3
    }
    
    
    
    GET recipes/_search
    {
      "query": {
        "match": {
          "name": "鱼"
        }
      },
      "sort": [
        {
          "rating": {
            "order": "desc"
          }
        }
      ],"aggs": {
        "type": {
          "terms": {
            "field": "type",
            "size": 10
          },"aggs": {
            "rated": {
              "top_hits": {
                "sort": [{
                  "rating": {"order": "desc"}
                }], 
                "size": 1
              }
            }
          }
        }
      }, 
      "size": 0,
      "from": 0
    }
    
    GET recipes/_search
    {
        "aggs": {
            "max_value": {
                "max": {
                    "field": "rating"
                }
            }
        },
        "size": 0
    }
    
    GET recipes/_search
    {
        "aggs": {
            "min_value": {
                "min": {
                    "field": "rating"
                }
            }
        },
        "size": 0
    }
    
    GET recipes/_search
    {
        "aggs": {
            "avg_value": {
                "avg": {
                    "field": "rating"
                }
            }
        },
        "size": 0
    }
    
    GET recipes/_search
    {
        "aggs": {
            "sum_value": {
                "sum": {
                    "field": "rating"
                }
            }
        },
        "size": 0
    }
    
    GET recipes/_search
    {
        "aggs": {
            "type_count": {
                "cardinality": {
                    "field": "type"
                }
            }
        },
        "size": 0
    }
    
    GET recipes/_search
    {
        "aggs": {
            "stat": {
                "stats": {
                    "field": "rating"
                }
            }
        },
        "size": 0
    }
    
    
    GET recipes/_search
    {
        "aggs": {
            "extended_stats": {
                "extended_stats": {
                    "field": "rating"
                }
            }
        },
        "size": 0
    }
    
    GET recipes/_search
    {
        "aggs": {
            "percentiles": {
                "percentiles": {
                    "field": "rating"
                }
            }
        },
        "size": 0
    }
    
    GET recipes/_search
    {
        "aggs": {
            "value_count": {
                "value_count": {
                    "field": "rating"
                }
            }
        },
        "size": 0
    }
    
    
    
    
    
    

    相关文章

      网友评论

          本文标题:4.1 指标聚合 ★★★

          本文链接:https://www.haomeiwen.com/subject/vsozahtx.html