From 9656d893d2d8e45bdaf432c217fe411ff8244562 Mon Sep 17 00:00:00 2001 From: Nikolai Alex Date: Fri, 19 Jul 2013 22:20:09 +0200 Subject: [PATCH] Adding a table panel for facets. A new panel with the name facets is added to kibana in order to display the terms of a facet query in a html table. Clicks on term names will narrow the search further. --- config.js | 2 +- panels/facets/editor.html | 19 +++++++++ panels/facets/module.html | 34 ++++++++++++++++ panels/facets/module.js | 81 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100755 panels/facets/editor.html create mode 100755 panels/facets/module.html create mode 100755 panels/facets/module.js diff --git a/config.js b/config.js index b81a2e33013ca..21b63cd610550 100644 --- a/config.js +++ b/config.js @@ -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'], } ); diff --git a/panels/facets/editor.html b/panels/facets/editor.html new file mode 100755 index 0000000000000..581eb58df7932 --- /dev/null +++ b/panels/facets/editor.html @@ -0,0 +1,19 @@ +
+ The facets panel displays the terms of a facet query in a table. If multiple queries are sent from a single panel the first query will be displayed. +
+ +
+
+
Field
+ + Field that is used for the facet. +
+
+ +
+
+
Size
+ + Maximum number of terms in the table. +
+
\ No newline at end of file diff --git a/panels/facets/module.html b/panels/facets/module.html new file mode 100755 index 0000000000000..ff4a65b0f3ecb --- /dev/null +++ b/panels/facets/module.html @@ -0,0 +1,34 @@ + + + + + + +
+
+ + + + + + + + + + + + + + + + + + +
TermsCount
+ Total: | + Other: | + Missing: +
+
+
+
\ No newline at end of file diff --git a/panels/facets/module.js b/panels/facets/module.js new file mode 100755 index 0000000000000..32bdfddf0be59 --- /dev/null +++ b/panels/facets/module.js @@ -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 : "
Last Elasticsearch Query
"+
+          'curl -XGET '+config.elasticsearch+'/'+$scope.index+"/_search?pretty -d'\n"+
+          angular.toJson(JSON.parse(request.toString()),true)+
+        "'
", + } + } + + 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(); + } + +});