Finding the query in agg_table.js context

Hi,

I'm trying to develop server side query analysis tool, and I'm modifying the src/ui/public/agg_table/agg_table.js

I was able to add some stuff, but what I would really like to to, is to get the query text (just like spy mode -> request) in this context.

Any help?

thanks!!! this is really important for me...

Hi @leofer,

I want to prefix this by recommending to not modify the Kibana source itself, but to instead implement things lika that as a plugin that provides a new visualization type.

That being said, what you are probably looking for is to get hold of the SearchSource and use the body property of the SearchSource._flatten() call's return value.

Thanks Felix for the prompt reply.

Doing this as a plugin is an interesting idea - working on plugin should improve maintenance. Can you please point me to an example plugin which uses SearchSource ?

The visualization type infrastructure provides an extensive abstraction over data retrieval and dashboard embedding. Since all built-in visualization are implemented as plugins as well, I would recommend to look at one of them (e.g. the data table visualization). Maybe you could copy the visualization, rename it and adapt it to your use-case. Unfortunately there is no authoritative documentation on writing visualization plugins, but there are several community-authored tutorials such as https://www.timroes.de/2015/12/06/writing-kibana-4-plugins-visualizations-using-data/. The official documentation also contains an overview of the basic structure of a plugin.

I read the official documentation of plugin development and everything I could find online, and SearchSource does look like what need - but I'm still not sure how to use it. Could you point me to an example of how to "get a hold of SearchSource" ?

thanks in advance,
Ofer

So...I added the following line:

    const p = Private(SearchSourceProvider).prototype._flatten();

inside the file:
$KIBANA_HOME/src/ui/public/agg_table/agg_table.js

within self.exportAsCsv (line 41).

I'm getting a Promise which seems to be some flashy concept of ES6, not sure what's that but found some ref here:

So I added a breakpoint in developer mode (chrome) and in the console I added

p.then(function(value) {
console.log('value: ' + value);
});

expecting finally to see my query logged in the console, whereas instead I'm getting the following error...help..please

angular.js:12477 TypeError: Cannot read property 'index' of undefined
at SourceAbstract.AbstractDataSourceProvider.SourceAbstract.get (_abstract.js:90)
at _root_search_source.js:17
at SourceAbstract.SearchSourceProvider.SearchSource._mergeProp (search_source.js:172)
at ittr (_abstract.js:316)
at index.js:2275
at index.js:3073
at baseForOwn (index.js:2046)
at index.js:3043
at baseMap (index.js:2274)
at Function.map (index.js:6710)
at ittr (_abstract.js:309)
at _abstract.js:324
at processQueue (angular.js:14745)
at angular.js:14761
at Scope.$eval (angular.js:15989)
at Scope.$digest (angular.js:15800)

You're trying to call the instance method _flatten() without and instance by accessing the prototype directly. In order to use the search source you have to get hold of an instance. You can either create your own using something like

const SearchSource = Private(SearchSourceProvider);
const searchSource = new SearchSource();

or use the searchSource of the savedObj (similar to how it is done in https://github.com/elastic/kibana/blob/b5527aebdc66c87e1e0c18f6537dc639ec261618/src/ui/public/visualize/visualize.js#L58). Alternatively you could use the query abstraction provided by Kibana's visualization layer. Which one is appropriate would depend on what you want to accomplish. If your code is available on GitHub, I could take a look and give more specific advice.

THANKS, but now I'm getting another error (below).

I have uploaded it to git, here: https://github.com/gorefbitim/kibana/commit/aa03e495a1c8d3858e13e8a94f5a6ef17c229075

The error ,

I put BreakPoint at line 64
console.log("AFTER");

Then I copy the following lines to the console on development mode (client side, chrome) and hit F8

    searchSource._flatten().then(function(value) {
        console.log('value: ' + value);
    });

I'm getting:

AFTER
TypeError: Cannot read property 'timeFieldName' of undefined
at Timefilter.get (timefilter.js:87)
at _root_search_source.js?422d:17
at SearchSourceProvider.SearchSource._mergeProp (search_source.js?5034:172)
at ittr (_abstract.js?851d:316)
at index.js:2275
at index.js:3073
at baseForOwn (index.js:2046)
at index.js:3043
at baseMap (index.js:2274)
at Function.map (index.js:6710)
at ittr (_abstract.js?851d:309)
at _abstract.js?851d:324
at processQueue (angular.js:14745)
at angular.js:14761
at Scope.$eval (angular.js:15989)
at Scope.$digest (angular.js:15800)
(anonymous) @ angular.js:12477
(anonymous) @ angular.js:9246
processQueue @ angular.js:14753
(anonymous) @ angular.js:14761
$eval @ angular.js:15989
$digest @ angular.js:15800
$apply @ angular.js:16097
(anonymous) @ angular.js:23554
dispatch @ jquery.js:4737
elemData.handle @ jquery.js:4549

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