Use Vega Visualization with Dynamic Data (Index)

Hi All,

I am beginner in Kibana and Elasticsearch.
When I try to use index with vegalite visualization, I am getting single bar with undefined CC_E field instead of showing colors w.r.t. CC_E(This is nominal field values are alphanumeric) and also I am not getting any EQP(This is alphanumeric field - Unique No. of values in this field are 7) on the x-axis.
Here is the code snippet.
{
"$schema": "https://vega.github.io/schema/vega-lite/v3.json",
"data":
{
"url": {
"%context%": true,
"index": "vizcheck"
},
},
"mark": "bar",
"encoding":
{
"x":
{
"field": "EQP",
"type": "nominal"
},
"y":
{
"field":"NoObj",
"aggregate": "count",
"type": "quantitative"
}
,
"color":
{
"field": "CC_E",
"type": "nominal"
}
}
}

I was looking for stacked bar graph. If any one can help I will be very thankful to you.

Thanks & Regards
Suhas Gupta

Hi All,

I am able to find the answer and posting it here.
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.3.1.json",
"autosize":
{
"type": "pad",
"resize": false
},
"data":
{
"url": {
"%context%": true,
"index": "vizcheck"
"body":
{
"aggs" : {
"eqpt_buckets": {
"composite" : {
"size": 5000,
"sources" :
[
{
"EPID":
{"terms" :
{
"field": "EPID"
}
}
},
{
"DATE":
{"terms" :
{"field": "DATE"
}
}
},
{
"CC_E":
{"terms" :
{"field": "CC_E"
}
}
},
{
"NoObj":
{
"terms":
{"field": "NoObj"
}
}
}
]
}
}
}
}
}
"format": {property: "aggregations.eqpt_buckets.buckets"}

},
  "transform": 
    [
      {"calculate": "datum.key.EPID", 
        "as": "EPID"
      },
      {"calculate": "datum.key.DATE", 
        "as": "DATE"},
      {"calculate": "datum.key.CC_E", 
      "as": "CC_E"
      },
      {"calculate": "datum.key.NoObj",
      "as": "NoObj"
      }
    ],
"mark": "bar",
 "config": 
 {
    "size": 
    {
      "height": 200,
      "width": 200
    },
}
"encoding": 
{
  "x": 
    {
        "field": "DATE",
        "type": "temporal",

    },
  "y": 
    {
        "field":"NoObj", 
        "aggregate": "sum",
        "type": "quantitative"
    }
    ,
  "color": 
    {
      "field": "CC_E", 
      "type": "nominal"
    },
  "row":
    {
      "field": "EPID",
      "type": "nominal"
    }
}

}

Main problem with earlier code was we need data to be formatted in the way bar graph needs. So first in the data group we are writing query to get the data and then using the same in below part of the code to draw the chart.

Thanks & Regards
Suhas Gupta

Glad you were able to find the solution! If you don't mind, could you mark this question as resolved? Thanks!

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