Link Search Menu Expand Document Documentation Menu

缺失值聚合

如果索引中的文档不包含聚合字段或聚合字段的值为 NULL,可以使用 missing 参数来指定此类文档应放入的桶的名称。

以下示例将所有缺失值添加到名为“N/A”的桶中。

GET opensearch_dashboards_sample_data_logs/_search
{
  "size": 0,
  "aggs": {
    "response_codes": {
      "terms": {
        "field": "response.keyword",
        "size": 10,
        "missing": "N/A"
      }
    }
  }
}

因为 min_doc_count 参数的默认值为 1,所以 missing 参数在其响应中不返回任何桶。将 min_doc_count 参数设置为 0 即可在响应中看到“N/A”桶。

GET opensearch_dashboards_sample_data_logs/_search
{
  "size": 0,
  "aggs": {
    "response_codes": {
      "terms": {
        "field": "response.keyword",
        "size": 10,
        "missing": "N/A",
        "min_doc_count": 0
      }
    }
  }
}

示例响应

...
"aggregations" : {
  "response_codes" : {
    "doc_count_error_upper_bound" : 0,
    "sum_other_doc_count" : 0,
    "buckets" : [
      {
        "key" : "200",
        "doc_count" : 12832
      },
      {
        "key" : "404",
        "doc_count" : 801
      },
      {
        "key" : "503",
        "doc_count" : 441
      },
      {
        "key" : "N/A",
        "doc_count" : 0
      }
    ]
  }
 }
}
剩余 350 字符

有问题?

想贡献?