

Adding Opensearch-Dashboards/Kibana filters to Vega visuals
source link: https://blog.davidvassallo.me/2023/09/08/adding-opensearch-dashboards-kibana-filters-to-vega-visuals/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Adding Opensearch-Dashboards/Kibana filters to Vega visuals
Opensearch-Dashboards and Kibana allow for the use of the “vega” library, which lets developers build an arbitrarily complex visualization. One of my favorite visuals which is not included in the standard visualization library is the “Sankey Diagram“. Since it’s not part and parcel of the preset charts offered by Opensearch Dashboards, we resort to Vega. Luckily, there is an excellent starting point here: https://www.elastic.co/blog/sankey-visualization-with-vega-in-kibana, which pretty much takes you 95% of the way.
But what if we’d like to embed the resulting Sankey diagram into our dashboard, and subsequently have our interactions with the vega Sankey diagram add and remove filters just like any other chart? This is our objective in this article.
So quick google search found someone with the same problem asking around the Elasticsearch forum here: https://discuss.elastic.co/t/update-kibana-filter-from-vega/295598, where they make reference to a “custom vega function” named KibanaAddfilter
.
More googling for the equivalent of this in Opensearch leads us to: https://forum.opensearch.org/t/os2-3-integration-with-vega/15107, where we are helpfully given a look into the the code:
const vegaFunctions = { opensearchDashboardsAddFilter: 'addFilterHandler' , opensearchDashboardsRemoveFilter: 'removeFilterHandler' , opensearchDashboardsRemoveAllFilters: 'removeAllFiltersHandler' , opensearchDashboardsSetTimeFilter: 'setTimeFilterHandler' , opensearchDashboardsVisEventTriggered: 'triggerExternalActionHandler' , }; |
So we know that the custom function equivalent is opensearchDashboardsAddFilter
, and it maps to a function named addFilterHandler
. Some more digging around in the code brings us to some more helpful comments as to what exactly we need to input into this function:
/** * @param {object} query Query DSL snippet, as used in the query DSL editor * @param {string} [index] as defined in OpenSearch Dashboards, or default if missing * @param {string} alias OpenSearch Query DSL's custom label for `opensearchDashboardsAddFilter`, as used in '+ Add Filter' */ async addFilterHandler(query, index, alias) { const indexId = await this .findIndex(Utils.handleNonStringIndex(index)); const filter = opensearchFilters.buildQueryFilter( Utils.handleInvalidQuery(query), indexId, alias ); this ._applyFilter({ filters: [filter] }); } |
We have all the information we need to go back to the original vega script and modify it so that when clicking on either side of the sankey diagram, we get a filter.
In vega-speak, “event handlers” are referred to as “signals“. Scrolling down to the very bottom of the original vega script, we see a couple of these signals already there:
// Clicking groupMark sets this signal to the filter values events: @groupMark:click! update: "..." |
So we need to modify the “update” property in that object. Fromour previous research, we know that we have to use opensearchDashboardsAddFilter
, which expects a DSL query… but how do we know which field to query on?
Aside: we modified the original sankey to show windows servers on the left, and windows event codes on the right
If we click on the left sankey column we’d like one field to be filtered, if we click on the right sankey column we’d like a different column filtered. Time to RTFM and see what signal “update” objects allow:
Ok, so we need an “expression”: Vega Expressions. And right there in the first few lines we have our answer:
So we have all the pieces in place to write our “update” property:
update: " datum.stack=='stk1' ? //here we use basically an if clause to ask, is the click on 'stk1' or not? opensearchDashboardsAddFilter({\"match_phrase\": { \"winlog.computer_name\": datum.grpId } }, 'winlogbeat-*') // if yes, call the opensearchDashboardsAddFilter with one field, set to datum.grpId (the value we clicked on) : opensearchDashboardsAddFilter({\"match_phrase\": { \"event.code\": datum.grpId } }, 'winlogbeat-*')" // if not, call the opensearchDashboardsAddFilter with another field, though also set to datum.grpId " |
NB the above is split over several lines for readability and includes comments. Please remove all newlines and comments when using this otherwise vega will complain
Here’s what we end up with:
Recommend
-
47
AWSWAF的默认dashboard数据显示的不实时,也不是特别明了,没有一些聚合指标,所以看起来就比较费力,那有没有第三方可以来展示AWSWAF呢?本文就教你如何使用Kibana来实时展示AWSWAF的状态。一、描述AWSWAFDashboards已经准备好使用仪表板(基于AmazonElasticsearch...
-
5
Adding DKIM support to OpenSMTPD with custom filters If you, like me, are running your own mail server, you might have looked at
-
11
TikTok is adding six new interactive, musical filtersThe first of which you can start using today.
-
14
OpenSearch Dashboards Hello! OpenSearch Dashboards is an open source search and analytics visualization derived from Kibana 7.10.2, and is currently in an alpha state. While we're still in the process of getting set up, we are...
-
18
OpenSearch: AWS fork of Elasticsearch and Kibana It's hard for me to know whether to feel bad for ES in this case. Did they bring it on themselves? Is Amazon too big and a bully?From my pe...
-
6
BMW's New Dashboards Are Adding Some Extra Google Magic
-
6
Performance Tuning Table Visuals With Filters Applied In Power BI Do you have a Power BI report with a table or a matrix on it, where there is a filter on the rows of the table? It’s a very co...
-
9
解决Kibana(OpenSearch)某些字段无法搜索问题 - netry - 博客园 最近在OpenSearch查看线上日志的时候,发现某个索引下有些字段无法直接在界面上筛选,搜索到也不高亮,非常的不方便,就像下面这样
-
11
This article is based on internal documentation from CyberSift, and since this seems to be a problem which others might run into, I’ve posted it here Problem scenario...
-
9
To determine the user that is signed in when making a request to your plugin server, or in more formal words the “authentication context” of a request you have two options Client Side This is not very secure...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK