# How To Catch Kibana Query Update?

**URL:** <https://discuss.elastic.co/t/how-to-catch-kibana-query-update/82387>\
**Category:** Kibana\
**Created:** [April 14, 2017, 7:26am UTC](https://discuss.elastic.co/t/how-to-catch-kibana-query-update/82387 "2017-04-14T07:26:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PRANSHU\_MIDHA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pranshu_midha/32/22533_2.png) [@PRANSHU\_MIDHA](https://discuss.elastic.co/u/PRANSHU_MIDHA)\
**Post date:** [April 14, 2017, 7:26am UTC](https://discuss.elastic.co/t/how-to-catch-kibana-query-update/82387/1 "2017-04-14T07:26:10Z")

</div>

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.

 ![](https://us1.discourse-cdn.com/elastic/original/3X/f/e/fefdef6a037a04d5e8d9c2abd6f44d4a347d8041.png)

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [April 14, 2017, 7:31pm UTC](https://discuss.elastic.co/t/how-to-catch-kibana-query-update/82387/2 "2017-04-14T19:31:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![PRANSHU\_MIDHA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pranshu_midha/32/22533_2.png) [@PRANSHU\_MIDHA](https://discuss.elastic.co/u/PRANSHU_MIDHA)\
**Post date:** [April 24, 2017, 10:40am UTC](https://discuss.elastic.co/t/how-to-catch-kibana-query-update/82387/3 "2017-04-24T10:40:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [May 1, 2017, 4:43pm UTC](https://discuss.elastic.co/t/how-to-catch-kibana-query-update/82387/4 "2017-05-01T16:43:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PRANSHU\_MIDHA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pranshu_midha/32/22533_2.png) [@PRANSHU\_MIDHA](https://discuss.elastic.co/u/PRANSHU_MIDHA)\
**Post date:** [May 2, 2017, 4:53am UTC](https://discuss.elastic.co/t/how-to-catch-kibana-query-update/82387/5 "2017-05-02T04:53:19Z")

</div>

Thank You very much Lukas!  
It worked!  
👍

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 30, 2017, 5:06am UTC](https://discuss.elastic.co/t/how-to-catch-kibana-query-update/82387/6 "2017-05-30T05:06:39Z")

</div>

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