栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

es - elasticsearch - aggs - metrics - cardinality

es - elasticsearch - aggs - metrics - cardinality

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

问:cardinality有什么特点?
答:

问:cardinality如何使用?
答:

# 删除
DELETE /cardinality_test

# 映射
PUT /cardinality_test
{
  "mappings": {
    "properties": {
      "name": {"type": "keyword"},
      "filter_type": {"type": "keyword"},
      "num": {"type": "integer"}
    }
  }
}

# 索引
POST /cardinality_test/_bulk?routing=1&refresh
{"index": {"_id": 1}}
{"name": "hello", "filter_type": "t1", "num": 3}
{"index": {"_id": 2}}
{"name": "me", "filter_type": "t2", "num": 5}
{"index": {"_id": 3}}
{"name": "me", "filter_type": "t1", "num": 18}
{"index": {"_id": 4}}
{"name": "hello", "filter_type": "t1", "num": 20}
{"index": {"_id": 5}}
{"name": "good", "filter_type": "t1", "num": 28}
{"index": {"_id": 6}}
{"name": "me", "filter_type": "t2", "num": 50}
{"index": {"_id": 7}}
{"name": "good", "filter_type": "t1", "num": 58}
{"index": {"_id": 8}}
{"name": "hello", "filter_type": "t1", "num": 88}

# 搜索
GET /cardinality_test/_search?size=0
{
  "aggs": {
    "cardinality_aggs": {
      "cardinality": {
        "field": "name",
        "precision_threshold": 100
      }
    }
  }
}

# 结果
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 8,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "cardinality_aggs" : {
      "value" : 3
    }
  }
}

# 搜索
GET /cardinality_test/_search?size=0
{
  "aggs": {
    "cardinality_aggs": {
      "cardinality": {
        "field": "type",
        "missing": "N/A"
      }
    }
  }
}

# 结果
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 8,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "cardinality_aggs" : {
      "value" : 1
    }
  }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/581386.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号