i'm trying to fetch some data from my index based on the event name matching exactly certain keyword but the catch is that i need the data of the current week and the previous week and also for few more previous weeks like i want to get the percentage difference of the current week's data vs prev week's data and more likewise.
Kindly help me asap as i'm stucked in this since a week and i need to complete my dashboard asap.
Thanks in advance!
I'm adding the search query of the console which gave me the required data in response but i'm unable to get the same in the vega-lite script.
The console query is
GET my_index/_search
{
"size": 0,
"aggs": {
"f": {
"terms": {
"field": "event.name",
"include": [
"match_keyword"
]
},
"aggs": {
"filters": {
"filters": {
"current": {
"key":"match_keyword",
"range": {
"@timestamp": {
"%timefilter%": true
}
}
},
"previous": {
"range": {
"@timestamp": {
"%timefilter%": true,
"shift": -1,
"unit": "week"
}
}
}
}
}
}
}
}
}
and being a begginer the vega-lite code that i've tried is this but it's not showing up anything
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {
"url": {
"%context%": true,
"index": "my_index",
"body": {
"aggs": {
"f": {
"terms": {"field": "event.name", "include": "match_keyword"},
"filters": {
"filters": {
"current": {"range": {"@timestamp": {"%timefilter%": true}}},
"previous": {
"range": {
"@timestamp": {
"%timefilter%": true,
"shift": -1,
"unit": "week"
}
}
}
}
}
}
},
"size": 0
}
},
"format": {"type": "json", "property": "aggregations.f.buckets"}
},
"transform": [
{
"calculate": "if (datum.previous.doc_count, datum.current.doc_count / datum.previous.doc_count-1, null)",
"as": "percent_diff"
},
{
"calculate": "if (datum['match_keyword'].doc_count, datum['match_keyword'].doc_count, null)",
"as": "current_result"
}
],
"vconcat": [
{
"title": "Percent change from 1 weeks ago",
"width": 250,
"height": 40,
"mark": "text",
"encoding": {
"text": {"field": "percent_diff"},
"size": {"value": 32},
"align": {"value": "center"},
"color": {
"condition": {"test": "datum['percent_diff'] < 0", "value": "red"},
"value": "green"
}
}
},
{
"title": "Current value",
"width": "container",
"mark": "text",
"encoding": {
"text": {"field": "current_result.doc_count"},
"fill": {"value": "black"},
"fontWeight": {"value": "bold"},
"align": {"value": "center"}
}
},
{
"title": "Previous value",
"width": "container",
"mark": "text",
"encoding": {
"text": {"field": "previous.doc_count", "format": ","},
"fill": {"value": "black"},
"fontWeight": {"value": "bold"},
"align": {"value": "center"}
}
}
]
}