Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a table panel for facets. #239

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ var config = new Settings(
kibana_index: "kibana-int",
modules: ['histogram','map','pie','table','stringquery','sort',
'timepicker','text','fields','hits','dashcontrol',
'column','derivequeries','trends','bettermap'],
'column','derivequeries','trends','bettermap', 'facets'],
}
);
19 changes: 19 additions & 0 deletions panels/facets/editor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="row-fluid">
The facets panel displays the terms of a facet query in a table. <strong>If multiple queries are sent from a single panel the first query will be displayed.</strong>
</div>

<div class="row-fluid">
<form class="form-inline">
<h6>Field</h6>
<input bs-typeahead="fields.list" type="text" ng-model="panel.field" ng-change="get_data()" placeholder="Facet field">
<span class="help-inline">Field that is used for the facet.</span>
</form>
</div>

<div class="row-fluid">
<form class="form-inline">
<h6>Size</h6>
<input type="number" ng-model="panel.size" ng-change="get_data()" placeholder="Maximum terms">
<span class="help-inline">Maximum number of terms in the table.</span>
</form>
</div>
34 changes: 34 additions & 0 deletions panels/facets/module.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<kibana-panel data-ng-controller='facets' data-ng-init='init()'>

<span style="position:absolute;right:0px;top:0px" class='panelextra pointer'>
<i bs-modal="'partials/modal.html'" class="icon-eye-open"></i>
</span>

<div style="height:{{row.height}};overflow-y:auto;overflow-x:hidden;" >
<div class="row-fluid">
<table class="table-hover table table-condensed table-striped">
<thead>
<tr>
<td><strong>Terms</strong></td>
<td><strong>Count</strong></td>
</tr>
</thead>
<tbody >
<tr data-ng-repeat="term in terms">
<td data-ng-bind="(term.term)" data-ng-click="update_query(term.term)"></td>
<td data-ng-bind="(term.count)"></td>
</tr>
<tfoot class="small">
<tr>
<td colspan="0">
<strong>Total: </strong><span data-ng-bind="(total)" /> |
<strong>Other: </strong><span data-ng-bind="(other)" /> |
<strong>Missing: </strong><span data-ng-bind="(missing)" />
</td>
</tr>
</tfoot>
</tbody>
</table>
</div>
</div>
</kibana-panel>
81 changes: 81 additions & 0 deletions panels/facets/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
angular.module('kibana.facets', []).controller('facets', function($scope, eventBus, fields) {

// Set and populate defaults
var _d = {
query : "*",
size : 20, // Number of terms in facets.
field : "" // Field that is used for the facet.
}

_.defaults($scope.panel,_d)

$scope.init = function() {
eventBus.register($scope,'time', function(event,time){set_time(time)});
eventBus.register($scope,'query', function(event, query) {
$scope.panel.query = _.isArray(query) ? query[0] : query;
$scope.get_data();
});

eventBus.broadcast($scope.$id,$scope.panel.group,'get_time')
}


$scope.get_data = function(segment,query_id) {
if(_.isUndefined($scope.index) || _.isUndefined($scope.time))
return

$scope.panel.loading = true;

// Create es query.
var request = $scope.ejs.Request().indices($scope.index);

var request = request
.facet(ejs.TermsFacet('facet')
.field($scope.panel.field)
.size($scope.panel.size)
.facetFilter(ejs.QueryFilter(
ejs.FilteredQuery(
ejs.QueryStringQuery($scope.panel.query || '*'),
ejs.RangeFilter($scope.time.field)
.from($scope.time.from)
.to($scope.time.to)
)))).size(0);

$scope.populate_modal(request);

var results = request.doSearch();

results.then(function(results) {
$scope.panel.loading = false;
$scope.total = results.facets.facet.total;
$scope.other = results.facets.facet.other;
$scope.missing = results.facets.facet.missing;
$scope.terms = results.facets.facet.terms;

$scope.$emit('render')
});
}

$scope.populate_modal = function(request) {
$scope.modal = {
title: "Inspector",
body : "<h5>Last Elasticsearch Query</h5><pre>"+
'curl -XGET '+config.elasticsearch+'/'+$scope.index+"/_search?pretty -d'\n"+
angular.toJson(JSON.parse(request.toString()),true)+
"'</pre>",
}
}

function set_time(time) {
$scope.time = time;
$scope.index = _.isUndefined(time.index) ? $scope.index : time.index
$scope.get_data();
}

$scope.update_query = function(term) {
$scope.panel.query = add_to_query($scope.panel.query,$scope.panel.field,term,false)
eventBus.broadcast($scope.$id,$scope.panel.group,'query',[$scope.panel.query]);
$scope.get_data();
}

});