From 0add791a189dedd79ae491e07b8da208c99e73ca Mon Sep 17 00:00:00 2001 From: Matt Bargar Date: Mon, 13 Feb 2017 10:50:18 -0500 Subject: [PATCH] Allow sorting and filtering on _type field (#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. Fixes #5684 --- .../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 62358fa61a4b..e9f5c6c3ef11 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 b44d822a6fd0..d2093cea6828 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 22a6e6b10dc6..0aaa512b308c 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 d8aad4ee3842..b87f6edced96 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 ff983d56de68..1415008d0c88 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');