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

es - elasticsearch - aggs - metrics - string

es - elasticsearch - aggs - metrics - string

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

问:string_stats有什么特点?
答:

问:string_stats如何使用?
答:

DELETE /string_stats_test

PUT /string_stats_test
{
  "mappings": {
    "properties": {
      "name": {"type": "keyword"}
    }
  }
}

POST /string_stats_test/_bulk
{"index": {"_id": 1}}
{"name": "hello"}
{"index": {"_id": 2}}
{"name": "good"}
{"index": {"_id": 3}}
{"name": "me"}
{"index": {"_id": 4}}
{"name": "kkk"}
{"index": {"_id": 5}}
{"name": "good"}


GET /string_stats_test/_search
{
  "size": 0,
  "aggs": {
    "string_stats_aggs": {
      "string_stats": {
        "field": "name",
        "show_distribution": true
      }
    }
  }
}

# 结果
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 5,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "string_stats_aggs" : {
      "count" : 5,
      "min_length" : 2,
      "max_length" : 5,
      "avg_length" : 3.6,
      "entropy" : 2.816340113853408,
      "distribution" : {
        "o" : 0.2777777777777778,
        "k" : 0.16666666666666666,
        "d" : 0.1111111111111111,
        "e" : 0.1111111111111111,
        "g" : 0.1111111111111111,
        "l" : 0.1111111111111111,
        "h" : 0.05555555555555555,
        "m" : 0.05555555555555555
      }
    }
  }
}

GET /string_stats_test/_search
{
  "size": 0,
  "aggs": {
    "string_stats_aggs": {
      "string_stats": {
        "field": "name",
        "script": {
          "lang": "painless",
          "source": "doc.name.value + params.param1",
          "params": {
            "param1": "ttt"
          }
        }
      }
    }
  }
}

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

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

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