Skip to content

Commit

Permalink
Allow sorting and filtering on _type field (#10311)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
elastic-jasper authored and Bargs committed Feb 13, 2017
1 parent 8033179 commit 21754a0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/fixtures/logstash_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' } ],
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/doc_table/__tests__/lib/get_sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('filterBarClickHandler', function () {
{
type: 'terms',
schema: 'segment',
params: { field: '_type' }
params: { field: 'non-filterable' }
}
]
});
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/index_patterns/_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 21754a0

Please sign in to comment.