es - elasticsearch - aggs - metrics - string

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

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存