【问题标题】:Compute the "fill rate" of a field in Elasticsearch计算 Elasticsearch 中字段的“填充率”
【发布时间】:2016-04-19 00:03:01
【问题描述】:

我想计算索引中有值的字段的比率。

我设法计算了有多少文档错过了该字段:

GET profiles/_search
{
  "aggs": {
    "profiles_wo_country": {
      "missing": {
        "field": "country"
      }
    }
  },
  "size": 0
}

我还计算了提交的文件数量:

GET profiles/_search
{
  "query": {
    "filtered": {
      "query": {"match_all": {}},
      "filter": {
        "exists": {
          "field": "country"
        }
      }
    }
  },
  "size": 0
}

当然我也可以得到索引中的文档总数。如何计算比率?

【问题讨论】:

  • (exists_count / total_docs) * 100((1 - missing_count) / total_docs) * 100 ?
  • @Val Right... 但是如何将其编码到 ES 查询/聚合/等中?
  • 你运行的是哪个 ES 版本?

标签: elasticsearch


【解决方案1】:

从查询中获取所需数字的一种简单方法是使用以下查询

POST profiles/_search?filter_path=hits.total,aggregations.existing.doc_count
{
  "size": 0,
  "aggs": {
    "existing": {
      "filter": {
        "exists": {
          "field": "tag"
        }
      }
    }
  }
}

你会得到这样的回应:

{
   "hits": {
      "total": 37258601
   },
   "aggregations": {
      "existing": {
        "doc_count": 9287160
      }
   }
}

然后在你的客户端代码中,你可以简单地做

fill_rate = (aggregations.existing.doc_count / hits.total) * 100

你可以走了。

【讨论】:

  • 这是有道理的,但我想知道是否可以直接做?在 Kibana 中获得情节?
猜你喜欢
  • 1970-01-01
  • 2021-07-26
  • 2018-03-29
  • 1970-01-01
  • 2019-02-06
  • 1970-01-01
  • 1970-01-01
  • 2018-04-09
  • 2018-03-13
相关资源
最近更新 更多