From 21754a07be3541e588606bec1af46b29487b8846 Mon Sep 17 00:00:00 2001 From: jasper Date: Mon, 13 Feb 2017 12:02:47 -0500 Subject: [PATCH] Allow sorting and filtering on _type field (#10311) Backports PR #10254 It was already possible to sort, aggregate, and filter on _type in ES but we didn't allow it in Kibana because Elasticsearch's APIs pre-5.0 didn't report mapping information for meta fields. Now that field stats returns searchable and aggregatable (including meta fields) we can safely determine if any field is filterable, sortable, or aggregatable without looking at the mappings. This PR simply includes the searchable and aggregatable information in the calculations that determine filterable and sortable status of a field. --- .../discover/components/field_chooser/discover_field.js | 2 +- src/fixtures/logstash_fields.js | 2 ++ src/ui/public/doc_table/__tests__/lib/get_sort.js | 4 ++-- .../public/filter_bar/__tests__/filter_bar_click_handler.js | 2 +- src/ui/public/index_patterns/_field.js | 4 ++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core_plugins/kibana/public/discover/components/field_chooser/discover_field.js b/src/core_plugins/kibana/public/discover/components/field_chooser/discover_field.js index 62358fa61a4b3..e9f5c6c3ef111 100644 --- a/src/core_plugins/kibana/public/discover/components/field_chooser/discover_field.js +++ b/src/core_plugins/kibana/public/discover/components/field_chooser/discover_field.js @@ -39,7 +39,7 @@ app.directive('discoverField', function ($compile) { ' Values such as foo-bar will be broken into foo and bar.'); } - if (!field.indexed) { + if (!field.indexed && !field.searchable) { warnings.push('This field is not indexed and might not be usable in visualizations.'); } } diff --git a/src/fixtures/logstash_fields.js b/src/fixtures/logstash_fields.js index b44d822a6fd03..d2093cea6828a 100644 --- a/src/fixtures/logstash_fields.js +++ b/src/fixtures/logstash_fields.js @@ -25,6 +25,8 @@ function stubbedLogstashFields() { ['_id', 'string', false, false, true, true ], ['_type', 'string', false, false, true, true ], ['_source', 'string', false, false, true, true ], + ['non-filterable', 'string', false, false, true, false], + ['non-sortable', 'string', false, false, false, false], ['custom_user_field', 'conflict', false, false, true, true ], ['script string', 'string', false, false, true, false, { script: '\'i am a string\'' } ], ['script number', 'number', false, false, true, false, { script: '1234' } ], diff --git a/src/ui/public/doc_table/__tests__/lib/get_sort.js b/src/ui/public/doc_table/__tests__/lib/get_sort.js index 22a6e6b10dc66..0aaa512b308c5 100644 --- a/src/ui/public/doc_table/__tests__/lib/get_sort.js +++ b/src/ui/public/doc_table/__tests__/lib/get_sort.js @@ -25,11 +25,11 @@ describe('docTable', function () { }); it('should sort by the default when passed an unsortable field', function () { - expect(getSort(['_id', 'asc'], indexPattern)).to.eql(defaultSort); + expect(getSort(['non-sortable', 'asc'], indexPattern)).to.eql(defaultSort); expect(getSort(['lol_nope', 'asc'], indexPattern)).to.eql(defaultSort); delete indexPattern.timeFieldName; - expect(getSort(['_id', 'asc'], indexPattern)).to.eql({ _score: 'desc' }); + expect(getSort(['non-sortable', 'asc'], indexPattern)).to.eql({ _score: 'desc' }); }); it('should sort in reverse chrono order otherwise on time based patterns', function () { diff --git a/src/ui/public/filter_bar/__tests__/filter_bar_click_handler.js b/src/ui/public/filter_bar/__tests__/filter_bar_click_handler.js index d8aad4ee38425..b87f6edced962 100644 --- a/src/ui/public/filter_bar/__tests__/filter_bar_click_handler.js +++ b/src/ui/public/filter_bar/__tests__/filter_bar_click_handler.js @@ -26,7 +26,7 @@ describe('filterBarClickHandler', function () { { type: 'terms', schema: 'segment', - params: { field: '_type' } + params: { field: 'non-filterable' } } ] }); diff --git a/src/ui/public/index_patterns/_field.js b/src/ui/public/index_patterns/_field.js index ff983d56de68d..1415008d0c882 100644 --- a/src/ui/public/index_patterns/_field.js +++ b/src/ui/public/index_patterns/_field.js @@ -40,10 +40,10 @@ export default function FieldObjectProvider(Private, shortDotsFilter, $rootScope const indexed = !!spec.indexed; const scripted = !!spec.scripted; - const sortable = spec.name === '_score' || ((indexed || scripted) && type.sortable); - const filterable = spec.name === '_id' || scripted || (indexed && type.filterable); const searchable = !!spec.searchable || scripted; const aggregatable = !!spec.aggregatable || scripted; + const sortable = spec.name === '_score' || ((indexed || aggregatable) && type.sortable); + const filterable = spec.name === '_id' || scripted || ((indexed || searchable) && type.filterable); const visualizable = aggregatable; obj.fact('name');