Newbie using OpenSearch, I believe version 2.3.
Trying to use Vega(v5) or Vega-Lite(v4) to create a visualization but finding that I can only get it to work when embedding data in the visualization. When switching this over to use an Index, the results just show ‘undefined’.
I am sure this is just a simple thing due to not understanding how to format the Vega logic when using the index but have tried and cannot figure it out.
Using vega with embedded data
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "A simple bar chart with embedded data.",
"background": "white",
"padding": 5,
"autosize":"fit-x",
"title": {
"text": ["Managers Rating Distribution", "Showing % of total rating"],
"frame": "group"
},
"style": "cell",
"data": [
{
"name": "source_0",
"values": [
{
"Documents": 1,
"Manager": "Rosanna Channing",
"Review Rating": "Meets Expectations"
},
{
"Documents": 1,
"Manager": "Rosanna Channing",
"Review Rating": "Meets Expectations"
},
{
"Documents": 1,
"Manager": "Rosanna Channing",
"Review Rating": "Meets Expectations"
},
{
"Documents": 1,
"Manager": "Rosanna Channing",
"Review Rating": "Meets Expectations"
},
{
"Documents": 1,
"Manager": "Rosanna Channing",
"Review Rating": "Meets Expectations"
},
{
"Documents": 1,
"Manager": "Rosanna Channing",
"Review Rating": "Company Maker"
},
** more rows... removed for readability **
{
"Documents": 1,
"Manager": "Netty Owyang",
"Review Rating": "Unsatisfactory"
},
{"Documents": 1, "Manager": "Netty Owyang", "Review Rating": "No Value"}
]
},
{
"name": "data_1",
"source": "source_0",
"transform": [
{
"type": "aggregate",
"groupby": ["Manager", "Review Rating"],
"ops": ["sum"],
"fields": ["Documents"],
"as": ["sum_Documents"]
},
{
"type": "stack",
"groupby": ["Manager"],
"field": "sum_Documents",
"sort": {"field": ["Review Rating"], "order": ["ascending"]},
"as": ["sum_Documents_start", "sum_Documents_end"],
"offset": "normalize"
},
{
"type": "filter",
"expr": "isValid(datum[\"sum_Documents\"]) && isFinite(+datum[\"sum_Documents\"])"
}
]
},
{
"name": "data_2",
"source": "source_0",
"transform": [
{
"type": "joinaggregate",
"as": ["total"],
"ops": ["sum"],
"fields": ["Documents"],
"groupby": ["Manager"]
},
{
"type": "formula",
"expr": "datum.Documents / datum.total",
"as": "percentage"
},
{
"type": "aggregate",
"groupby": ["Manager", "Review Rating"],
"ops": ["sum", "sum"],
"fields": ["Documents", "percentage"],
"as": ["sum_Documents", "sum_percentage"]
},
{
"type": "stack",
"groupby": ["Manager"],
"field": "sum_Documents",
"sort": {"field": ["Review Rating"], "order": ["ascending"]},
"as": ["sum_Documents_start", "sum_Documents_end"],
"offset": "normalize"
},
{
"type": "filter",
"expr": "isValid(datum[\"sum_Documents\"]) && isFinite(+datum[\"sum_Documents\"])"
}
]
}
],
"signals": [
{"name": "y_step", "value": 50},
{
"name": "height",
"update": "bandspace(domain('y').length, 0.1, 0.05) * y_step"
}
],
"marks": [
{
"name": "layer_0_marks",
"type": "rect",
"style": ["bar"],
"from": {"data": "data_1"},
"encode": {
"update": {
"fill": {"scale": "layer_0_color", "field": "Review Rating"},
"ariaRoleDescription": {"value": "bar"},
"description": {
"signal": "\"Sum of Documents: \" + (format(datum[\"sum_Documents_end\"]-datum[\"sum_Documents_start\"], \".0%\")) + \"; Manager: \" + (isValid(datum[\"Manager\"]) ? datum[\"Manager\"] : \"\"+datum[\"Manager\"]) + \"; Review Rating: \" + (isValid(datum[\"Review Rating\"]) ? datum[\"Review Rating\"] : \"\"+datum[\"Review Rating\"])"
},
"x": {"scale": "x", "field": "sum_Documents_end"},
"x2": {"scale": "x", "field": "sum_Documents_start"},
"y": {"scale": "y", "field": "Manager"},
"height": {"signal": "max(0.25, bandwidth('y'))"}
}
}
},
{
"name": "layer_1_marks",
"type": "text",
"style": ["text"],
"from": {"data": "data_2"},
"encode": {
"update": {
"dx": {"value": -15},
"dy": {"value": 0},
"fill": {"scale": "layer_1_color", "field": "Review Rating"},
"description": {
"signal": "\"Percentage: \" + (format(datum[\"sum_Documents_end\"]-datum[\"sum_Documents_start\"], \".0%\")) + \"; Manager: \" + (isValid(datum[\"Manager\"]) ? datum[\"Manager\"] : \"\"+datum[\"Manager\"]) + \"; Review Rating: \" + (isValid(datum[\"Review Rating\"]) ? datum[\"Review Rating\"] : \"\"+datum[\"Review Rating\"]) + \"; Sum of percentage: \" + (format(datum[\"sum_percentage\"], \".0%\"))"
},
"x": {"scale": "x", "field": "sum_Documents_end"},
"y": {"scale": "y", "field": "Manager", "band": 0.5},
"text": {"signal": "format(datum[\"sum_percentage\"], \".0%\")"},
"align": {"value": "center"},
"baseline": {"value": "middle"}
}
}
}
],
"scales": [
{
"name": "x",
"type": "linear",
"domain": [0, 1],
"range": [0, {"signal": "width"}],
"nice": true,
"zero": true
},
{
"name": "y",
"type": "band",
"domain": {
"fields": [
{"data": "data_1", "field": "Manager"},
{"data": "data_2", "field": "Manager"}
],
"sort": true
},
"range": {"step": {"signal": "y_step"}},
"paddingInner": 0.1,
"paddingOuter": 0.05
},
{
"name": "layer_0_color",
"type": "ordinal",
"domain": {"data": "data_1", "field": "Review Rating", "sort": true},
"range": "category"
},
{
"name": "layer_1_color",
"type": "ordinal",
"domain": {"data": "data_2", "field": "Review Rating", "sort": true},
"range": ["white"]
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"gridScale": "y",
"grid": true,
"tickCount": {"signal": "ceil(width/40)"},
"domain": false,
"labels": false,
"aria": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
},
{
"scale": "x",
"orient": "bottom",
"grid": false,
"title": "Percentage",
"format": ".0%",
"labelFlush": true,
"labelOverlap": true,
"tickCount": {"signal": "ceil(width/40)"},
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"grid": false,
"title": "Manager",
"zindex": 0
}
],
"legends": [
{"fill": "layer_0_color", "symbolType": "square", "title": "Review Rating"}
]
}
I can produce this visualization
When I try to switch this to use our index, I just get an Undefined result.
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "Manager Rating distribution by percent.",
"background": "white",
"padding": 5,
"autosize":"fit-x",
"title": {
"text": ["Managers Rating Distribution", "Showing % of total rating"],
"frame": "group"
},
"style": "cell",
"data": [
{
"name": "source_0",
"url":{ "index":"hc_ep_perf_ratings_mgr*" }
},
{
"name": "data_1",
"source": "source_0",
"transform": [
{
"type": "aggregate",
"groupby": ["Manager", "Review Rating"],
"ops": ["sum"],
"fields": ["Document ID"],
"as": ["sum_Documents"]
},
{
"type": "stack",
"groupby": ["Manager"],
"field": "sum_Documents",
"sort": {"field": ["Review Rating"], "order": ["ascending"]},
"as": ["sum_Documents_start", "sum_Documents_end"],
"offset": "normalize"
},
{
"type": "filter",
"expr": "isValid(datum[\"sum_Documents\"]) && isFinite(+datum[\"sum_Documents\"])"
}
]
},
{
"name": "data_2",
"source": "source_0",
"transform": [
{
"type": "joinaggregate",
"as": ["total"],
"ops": ["sum"],
"fields": ["Document ID"],
"groupby": ["Manager"]
},
{
"type": "formula",
"expr": "datum.Documents / datum.total",
"as": "percentage"
},
{
"type": "aggregate",
"groupby": ["Manager", "Review Rating"],
"ops": ["sum", "sum"],
"fields": ["Document ID", "percentage"],
"as": ["sum_Documents", "sum_percentage"]
},
{
"type": "stack",
"groupby": ["Manager"],
"field": "sum_Documents",
"sort": {"field": ["Review Rating"], "order": ["ascending"]},
"as": ["sum_Documents_start", "sum_Documents_end"],
"offset": "normalize"
},
{
"type": "filter",
"expr": "isValid(datum[\"sum_Documents\"]) && isFinite(+datum[\"sum_Documents\"])"
}
]
}
],
"signals": [
{"name": "y_step", "value": 50},
{
"name": "height",
"update": "bandspace(domain('y').length, 0.1, 0.05) * y_step"
}
],
etc. Rest remains the same as before.
The index does have the “Manager” field and the “Review Rating” field. I was trying to update the visualization to not need the Documents:1 by changing to use a “count” aggregation instead of “sum” but it didnt make a difference.