Kibana Vega bar chart errors

Hello,
I am trying to produce a bar chart in Kibana using Vega.
I use Vega because I have to use nested fields, and it seems there are not other options.
This is my script:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "title": "Event counts from all indexes",
  data: {
    url: {
      %context%: true
      %timefield%: timestamp
      index: search-sonarqube-telemetry-2021-merged
      body: {
        "aggs": {
          "languages": {
            "terms": { "field": "plugins.name.keyword"}  
          }
        }
        size: 0
      }
    }
    format: {property: "aggregations.languages.buckets" }
  }
  
 
  mark: bar

  encoding: {
    x: {
      field: buckets.key
      type: nominal
      axis: { title: null }
    }
    y: {
      field: buckets.doc_count
      type: quantitative
      axis: { title: "Document count" }
    }
    
  }
    
}

I get the warnings:

  • Infinite extent for field "buckets.doc_count_start": [Infinity, -Infinity]

  • Infinite extent for field "buckets.doc_count_end": [Infinity, -Infinity]

and everything is empty.

If I try to debug, I see the source_0 but not the data_0.

What is wrong in my script?
Thanks

I found the problem.
I defined the property as aggregations.languages.buckets, but the I was defined the fields as buckets.key and buckets.doc_count in the encoding.
It was enough to replace key and doc_count to buckets.key and buckets.doc_count and it worked.
Actually it was not finding the fields because inside aggregations.languages.buckets we don't have a repetition of buckets.

2 Likes

Could you post your final code? I don't understand the fix you described. Thanks!

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  data: {
    name: "aggregations"
    url: {
      %context%: true
      %timefield%: timestamp
      index: search-sonarqube-telemetry-*
      body: {
        "aggs": {
          "languages": {
            "terms": { "field": "plugins.name.keyword"}  
          }
        }
        size: 0
      }
    }
    format: {property: "aggregations.languages.buckets" }
  }
 
  encoding: {
    y: {
      field: "key"
      type: nominal
      axis: { 
        title: null 
      }
      sort: {
        order: "descending"
      }
    }
    x: {
      field: "doc_count"
      type: quantitative
      axis: { title: "Document count" }
    }
  }


  "config": {
    "axisY": {
      "labelFontSize": 30
    }
    "axisX": {
      "labelFontSize": 15,
      titleFontSize: 20
    }
  }

  
  "layer": [
    {
      "mark": {
        type: "bar"
      },
      encoding: {
        y: {
          field: "key"
          type: nominal
          axis: { 
            title: null,
          }
          sort: {
            order: "descending"
          }
        }
        x: {
          field: "doc_count"
          type: quantitative
          axis: { title: "Document counts" }
        }
      }
    }, 
    {
      "mark": {
        "type": "text",
        "align": "right",
        "baseline": "middle",
        "dx": -20,
        fontSize:25,
        color: white
      },
      "encoding": {
        "text": {
          "field": "doc_count", "type": "quantitative",
                  "format": ","
        }
        y: {
          field: "key"
          type: nominal
          axis: { 
            title: null
          }
          sort: {
            order: "descending"
          }
        }
        x: {
          field: "doc_count"
          type: quantitative
          axis: { title: "Document counts" }
        }
      }
    }
  ]
  
  


}   
1 Like

That works, thank you!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.