Skip to content

Instantly share code, notes, and snippets.

@michaelkeevildown
Created December 5, 2018 15:32
Show Gist options
  • Save michaelkeevildown/c875da5bcb245ee884dfd5518d36afde to your computer and use it in GitHub Desktop.
Save michaelkeevildown/c875da5bcb245ee884dfd5518d36afde to your computer and use it in GitHub Desktop.
Kibana Vega - Percentage of X in a whole index

Raw Data

The below can be copied and pasted straight into Kibana Dev Tools:

POST percentage/_doc
{
  "stage": 1
}

POST percentage/_doc
{
  "stage": 1
}

POST percentage/_doc
{
  "stage": 2
}

POST percentage/_doc
{
  "stage": 3
}

POST percentage/_doc
{
  "stage": 3
}

Raw Vega JSON Object

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "title": "Percentage of hits",
  "data": {
    "url": {
      "index": "percentage",
      "body": {
        "query": {
          "match": {
            "stage" : 1
          }
        }
        "aggs": {"total": {"global": {}}},
        "size": 0
      }
    }
  },
  "transform": [
    {
      "calculate": "datum.hits.total / datum.aggregations.total.doc_count",
      "as": "ratio"
    }
  ],
  "layer": [
    {
      "mark": "text",
      "encoding": {
        "text": {
          "field": "ratio",
          "type": "quantitative",
          "format": "p"
        }
      }
    }
  ],
  "config": {
    "text": {
      "fontSize": 100
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment