How To Catch Kibana Query Update?


(Pranshu Midha) #1

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.


(Lukas Olson) #2

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?


(Pranshu Midha) #3

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.


(Lukas Olson) #4

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);
  }
});

(Pranshu Midha) #5

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


(system) #6

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