es - elasticsearch - aggs - metrics - value

es - elasticsearch - aggs - metrics - value,第1张

es - elasticsearch - aggs - metrics - value

世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程

问:value_count有什么特点?
答:

问:value_count如何使用?
答:

DELETE /value_count_test

PUT /value_count_test
{
  "mappings": {
    "properties": {
      "type": {"type": "integer"},
      "num": {"type": "integer"},
      "date": {"type": "date"}
    }
  }
}

POST /value_count_test/_doc/1
{
  "type": 1,
  "num": 3,
  "date": "2021-09-08"
}


POST /value_count_test/_doc/2
{
  "type": 2,
  "num": 7,
  "date": "2021-09-08"
}


POST /value_count_test/_doc/3
{
  "name": "me",
  "type": 1,
  "num": 5,
  "date": "2021-09-08"
}

POST /value_count_test/_doc/4
{
  "type": 1,
  "num": 1,
  "date": "2019-07-18"
}

POST /value_count_test/_doc/5
{
  "type": 2,
  "num": 9,
  "date": "2019-07-18"
}

GET /value_count_test/_search
{
  "size": 0,
  "aggs": {
    "tm_aggs": {
      "terms": {
        "field": "type",
        "size": 10
      },
      "aggs": {
        "value_count_aggs": {
          "value_count": {
            "field": "num"
          }
        }
      }
    }
  }
}

# 结果
{
  "took" : 8,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 5,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "tm_aggs" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : 1,
          "doc_count" : 3,
          "value_count_aggs" : {
            "value" : 3
          }
        },
        {
          "key" : 2,
          "doc_count" : 2,
          "value_count_aggs" : {
            "value" : 2
          }
        }
      ]
    }
  }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5638607.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存