From 119f58385a2cbe238e5a8cdf96535c51c56cde02 Mon Sep 17 00:00:00 2001 From: lukasolson Date: Fri, 14 Nov 2014 10:30:13 -0700 Subject: [PATCH 1/2] Don't allow sorting on geo_point In discover, if you add a field of type geo_point to your search, and then try to sort on that field, the app errors out. It doesn't make sense to allow sorting on geo_point as this is not supported by ElasticSearch. Perhaps in the future we can allow sorting geo_point by distance from a given location. --- .../discover/directives/table_header.js | 10 ++++--- .../specs/apps/discover/directives/table.js | 27 ++++++++++--------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/kibana/plugins/discover/directives/table_header.js b/src/kibana/plugins/discover/directives/table_header.js index 1a046f0f3ec6f..eb3bb8ae84b10 100644 --- a/src/kibana/plugins/discover/directives/table_header.js +++ b/src/kibana/plugins/discover/directives/table_header.js @@ -14,9 +14,13 @@ define(function (require) { }, template: headerHtml, controller: function ($scope) { + var sortableField = function (field) { + var mapping = $scope.mapping[field]; + return mapping && mapping.indexed && mapping.type !== 'geo_point'; + }; + $scope.headerClass = function (column) { - if (!$scope.mapping) return; - if ($scope.mapping[column] && !$scope.mapping[column].indexed) return; + if (!sortableField(column)) return; var sorting = $scope.sorting; var defaultClass = ['fa', 'fa-sort', 'table-header-sortchange']; @@ -45,7 +49,7 @@ define(function (require) { }; $scope.sort = function (column) { - if ($scope.mapping[column] && !$scope.mapping[column].indexed) return; + if (!sortableField(column)) return; var sorting = $scope.sorting || []; $scope.sorting = [column, sorting[1] === 'asc' ? 'desc' : 'asc']; }; diff --git a/test/unit/specs/apps/discover/directives/table.js b/test/unit/specs/apps/discover/directives/table.js index e6aadf8078c2d..732ad46c29a1b 100644 --- a/test/unit/specs/apps/discover/directives/table.js +++ b/test/unit/specs/apps/discover/directives/table.js @@ -13,7 +13,7 @@ define(function (require) { var $parentScope, $scope, config; - // Stub out a minimal mapping of 3 fields + // Stub out a minimal mapping of 4 fields var mapping = { bytes: { indexed: true, @@ -26,6 +26,10 @@ define(function (require) { timestamp: { indexed: true, type: 'date' + }, + geo: { + indexed: true, + type: 'geo_point' } }; @@ -156,6 +160,11 @@ define(function (require) { done(); }); + it('should NOT sort geo_point fields', function (done) { + $scope.sort('geo'); + expect($scope.sorting).to.be(undefined); + done(); + }); }); describe('moving columns', function () { @@ -174,10 +183,10 @@ define(function (require) { }); it('shouldnt move the last column to the right', function () { - expect($scope.columns[2]).to.be('timestamp'); + expect($scope.columns[3]).to.be('geo'); - $scope.moveRight('timestamp'); - expect($scope.columns[2]).to.be('timestamp'); + $scope.moveRight('geo'); + expect($scope.columns[3]).to.be('geo'); }); it('should move columns to the left', function () { @@ -334,13 +343,7 @@ define(function (require) { it('should have a row for each field', function () { var rows = $details.find('tr'); var row = $scope.row; - expect($details.find('tr').length).to.be(3); - }); - - it('should have a row for each field', function () { - var rows = $details.find('tr'); - var row = $scope.row; - expect($details.find('tr').length).to.be(3); + expect($details.find('tr').length).to.be(_.keys(mapping).length); }); describe('filtering', function () { @@ -397,7 +400,7 @@ define(function (require) { }); it('should render even when the row source contains a field with the same name as a meta field', function () { - expect($details.find('tr').length).to.be(4); + expect($details.find('tr').length).to.be(_.keys(mapping).length); }); }); From 1baa52c1595e7078c4d875544a28f2c32380f05b Mon Sep 17 00:00:00 2001 From: lukasolson Date: Wed, 19 Nov 2014 15:35:38 -0700 Subject: [PATCH 2/2] Don't allow sorting on geo_shape or attachment either --- src/kibana/plugins/discover/directives/table_header.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/kibana/plugins/discover/directives/table_header.js b/src/kibana/plugins/discover/directives/table_header.js index eb3bb8ae84b10..ce770a9018208 100644 --- a/src/kibana/plugins/discover/directives/table_header.js +++ b/src/kibana/plugins/discover/directives/table_header.js @@ -14,9 +14,10 @@ define(function (require) { }, template: headerHtml, controller: function ($scope) { + var unsortableFields = ['geo_point', 'geo_shape', 'attachment']; var sortableField = function (field) { var mapping = $scope.mapping[field]; - return mapping && mapping.indexed && mapping.type !== 'geo_point'; + return mapping && mapping.indexed && !_.contains(unsortableFields, mapping.type); }; $scope.headerClass = function (column) {