How To Catch Kibana Query Update?

I have been building a Kibana plugin.And currently I am able to catch the query update on dashboard for my plugin using :

$scope.$watch(getAppState,function(appState){

$scope.state = appState;
$scope.query=$scope.state.query.query_string.query;
console.log($scope.query);
$http.get(" elastic search url ");
},true);

But the problem is on every key press on the query search bar, kibana is fetching data from elastic search. And this sometimes slows down my elastic search.
Is there any way in which I can catch the event of search event of kibana? I know the search button fires filterResults() function of kibana.

Could you provide the version of Kibana you're using?

Are you trying to log out every request to Elasticsearch, or only search queries, or what exactly?

My Kibana version is 4.3.0
And on every key press in the search bar it sends an http get request to elasticsearch.
It should only send the request when the query is submitted.

Instead of watching the appState for changes (which is updated on every key press), you'll want to watch for save_with_changes events:

const state = getAppState();
$scope.$listen(state, 'save_with_changes', function (diff) {
  if (diff.includes('query')) {
    console.log(state.query);
  }
});
1 Like

Thank You very much Lukas!
It worked!
:+1:

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