elasticsearch 在Vega中引用子bucket的语法,elasticsearch,kibana,vega,elasticsearch,Kibana,Vega" /> elasticsearch 在Vega中引用子bucket的语法,elasticsearch,kibana,vega,elasticsearch,Kibana,Vega" />

elasticsearch 在Vega中引用子bucket的语法

elasticsearch 在Vega中引用子bucket的语法,elasticsearch,kibana,vega,elasticsearch,Kibana,Vega,我有一个Elasticsearch(6.2)查询,返回以下JSON: "aggregations": { "per_buyer": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "Example-buyer", "doc_count": 45, "per_cart": {

我有一个Elasticsearch(6.2)查询,返回以下JSON:

"aggregations": {
  "per_buyer": {
    "doc_count_error_upper_bound": 0,
    "sum_other_doc_count": 0,
    "buckets": [
      {
        "key": "Example-buyer",
        "doc_count": 45,
        "per_cart": {
          "doc_count_error_upper_bound": 0,
          "sum_other_doc_count": 6,
          "buckets": [
            {
              "key": "397105FB",
              "doc_count": 8,
              "net": {
                "value": 10
} } ] } } ] } }
vega“format”字段显示每个“per_cart”桶的数据的正确语法是什么?任何比聚合.per\u buyer.bucket更深的内容都会返回错误
。聚合.per\u buyer.bucket.per\u购物车未定义
VEGA_DEBUG.view.data
显示一些
聚合.per_buyer.Bucket
有一个“per_cart”对象,而这个对象又有Bucket。(进行过滤,使所有存储桶都具有per_cart对象,而不会更改任何内容。)


我之前在上问过这个问题,但没有成功。

很抱歉,我错过了讨论论坛上的请求。在这里交叉张贴我的答案:

@Steven_Ensslen您的
格式
必须是
聚合.per_buyer.bucket
,因为这是您需要的数据列表。该bucket中的每个数据元素都可能包含一个子bucket列表,您必须从Vega本身访问该列表。现在,如果子列表始终只有一个bucket(例如,如果您对每个主bucket的总数求和),您可以直接从标记访问它,例如
datum.per_cart.bucket[0].net.value
,或者您可以创建一个公式转换,将该值复制到顶级字段中,例如
{type:'formula',as:'net_value',expr:'datum.per_cart.bucket[0].net.value'}
,并使用标记中的
净值
字段。另一方面,如果子列表中有多个项目,则可以使用
展平
转换将子存储桶展平为非层次化的项目列表,然后使用各种转换将数据转换为所需的格式

p.S.“展平”变换可能在6.3或6.4之前不可用