Skip to content

Commit

Permalink
Add explicit format parameter to docvalue_fields requests (#22771)
Browse files Browse the repository at this point in the history
Fixes #22484

Elasticsearch 6.4 added an optional `format` parameter for doc_value
fields. In 6.x if the param is not included it defaults to returning
the same values we see in scripted fields. In 7.0 this is changing to
use the mapping configured format by default. In kibana we want our date
values in ISO format, so this PR future proofs us for 7.0. It also eliminates
deprecation warnings ES is returning due to the missing param, which is
currently spamming some users.
  • Loading branch information
Bargs authored Sep 7, 2018
1 parent 12699d1 commit 4447523
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ui/public/agg_types/__tests__/metrics/top_hit.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('Top hit metric', function () {
it('requests both source and docvalues_fields for non-text aggregatable fields', function () {
init({ field: 'bytes' });
expect(aggDsl.top_hits._source).to.be('bytes');
expect(aggDsl.top_hits.docvalue_fields).to.eql([ 'bytes' ]);
expect(aggDsl.top_hits.docvalue_fields).to.eql([ { field: 'bytes', format: 'use_field_mapping' } ]);
});

it('requests just source for aggregatable text fields', function () {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/agg_types/metrics/top_hit.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const topHitMetricAgg = new MetricAggType({
};
} else {
if (field.readFromDocValues) {
output.params.docvalue_fields = [ field.name ];
output.params.docvalue_fields = [ { field: field.name, format: 'use_field_mapping' } ];
}
output.params._source = field.name === '_source' ? true : field.name;
}
Expand Down
4 changes: 3 additions & 1 deletion src/ui/public/courier/search_source/search_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,9 @@ export function SearchSourceProvider(Promise, Private, config) {
if (flatData.body._source) {
// exclude source fields for this index pattern specified by the user
const filter = fieldWildcardFilter(flatData.body._source.excludes);
flatData.body.docvalue_fields = flatData.body.docvalue_fields.filter(filter);
flatData.body.docvalue_fields = flatData.body.docvalue_fields.filter(
docvalueField => filter(docvalueField.field)
);
}

// if we only want to search for certain fields
Expand Down
15 changes: 13 additions & 2 deletions src/ui/public/index_patterns/__tests__/_get_computed_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,19 @@ describe('get computed fields', function () {
});

it('should request date fields as docvalue_fields', function () {
expect(fn().docvalueFields).to.contain('@timestamp');
expect(fn().docvalueFields).to.not.contain('bytes');
const docvalueFields = fn().docvalueFields;
const docvalueFieldNames = docvalueFields.map(field => field.field);

expect(docvalueFields).to.have.length(3);
expect(docvalueFieldNames).to.contain('@timestamp');
expect(docvalueFieldNames).to.contain('time');
expect(docvalueFieldNames).to.contain('utc_time');
});

it('should request date field doc values in date_time format', function () {
const docvalueFields = fn().docvalueFields;
const timestampField = docvalueFields.find((field) => field.field === '@timestamp');
expect(timestampField).to.have.property('format', 'date_time');
});

it('should not request scripted date fields as docvalue_fields', function () {
Expand Down
8 changes: 7 additions & 1 deletion src/ui/public/index_patterns/_get_computed_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ export function getComputedFields() {
const scriptFields = {};
let docvalueFields = [];

docvalueFields = _.map(_.reject(self.fields.byType.date, 'scripted'), 'name');
docvalueFields = _.reject(self.fields.byType.date, 'scripted')
.map((dateField) => {
return {
field: dateField.name,
format: 'date_time',
};
});

_.each(self.getScriptedFields(), function (field) {
scriptFields[field.name] = {
Expand Down

0 comments on commit 4447523

Please sign in to comment.