I have this working now. I've switched to full Vega from Vega-lite. Some of this is from a Google Group Post and I'm still not sure how much of it is required, but this works:
{
"$schema": "https://vega.github.io/schema/vega/v3.0.json",
"config": {"title": {"offset": 20, "fontSize": 16}},
"title": {"text": "Outstanding Balances"},
"padding": 10,
"autosize": {"type": "pad"},
"data": [
{
"name": "esHavingQuery",
"url": {
"%context%": true,
"%timefield%": "@timestamp",
"index": "transaction*",
"body": {
"size": 0,
"aggregations": {
"perCart": {
"terms": {"script": {"source": "doc['cart_id'].value.substring(0,8).toUpperCase();"}},
"aggregations": {
"net": {"sum": {"field": "ticket.after_fees_price"}},
"balance_owing": {
"bucket_selector": {
"buckets_path": {"NetOwing": "net"},
"script": "params.NetOwing > 0"
}
}
}
}
}
}
},
"format": {"property": "aggregations.perCart.buckets"},
"transform": [
{"type": "formula", "as": "x_position", "expr": "width * 1 / 3"},
{"type": "formula", "as": "line_height", "expr": "20"},
{"type": "formula", "as": "outstanding_balance", "expr": "format(datum.net.value,'$.2f')"},
{"type": "stack", "groupby": ["x_position"], "field": "line_height", "as": ["y0", "y1"]}
]
},
{"name": "Header", "values": [{"column1": "Cart Number", "column2": "Balance"}]}
],
"marks": [
{
"type": "text",
"from": {"data": "Header"},
"encode": {
"enter": {
"x": 0,
"y": {"field": "y0"},
"align": {"value": "left"},
"text": {"field": "column1"},
"fontSize": {"value": 14}
}
}
},
{
"type": "text",
"from": {"data": "Header"},
"encode": {
"enter": {
"x": {"offset": 200},
"y": {"field": "y0"},
"align": {"value": "right"},
"text": {"field": "column2"},
"fontSize": {"value": 14}
}
}
},
{
"type": "text",
"from": {"data": "esHavingQuery"},
"encode": {
"enter": {
"x": 0,
"y": {"field": "y0", "offset": 25},
"align": {"value": "left"},
"text": {"field": "key"}
}
}
},
{
"type": "text",
"from": {"data": "esHavingQuery"},
"encode": {
"enter": {
"x": {"offset": 200},
"y": {"field": "y0", "offset": 25},
"align": {"value": "right"},
"text": {"field": "outstanding_balance"}
}
}
}
]
}