Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting] Correct the docvalue_fields params in the search query Download CSV from Dashboard Panel #52833

Merged
merged 3 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion x-pack/legacy/plugins/reporting/export_types/csv/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@

import { JobDocPayload, JobParamPostPayload, ConditionalHeaders, RequestFacade } from '../../types';

interface DocValueField {
field: string;
format: string;
}

interface SortOptions {
order: string;
unmapped_type: string;
}

export interface JobParamPostPayloadDiscoverCsv extends JobParamPostPayload {
state?: {
query: any;
sort: any[];
sort: Array<Record<string, SortOptions>>;
docvalue_fields: DocValueField[];
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ export async function generateCsvSearch(

let payloadQuery: QueryFilter | undefined;
let payloadSort: any[] = [];
let docValueFields: any[] | undefined;
if (jobParams.post && jobParams.post.state) {
({
post: {
state: { query: payloadQuery, sort: payloadSort = [] },
state: { query: payloadQuery, sort: payloadSort = [], docvalue_fields: docValueFields },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elastic/kibana-app can you help us understand why the docvalue_fields info is part of the state that we get from the panel info? It means the id of the saved search doc isn't enough to derive an actual ES query - the state data is additional information.

},
} = jobParams);
}
Expand Down Expand Up @@ -119,7 +120,15 @@ export async function generateCsvSearch(
},
};
}, {});
const docValueFields = indexPatternTimeField ? [indexPatternTimeField] : undefined;

if (indexPatternTimeField) {
if (docValueFields) {
docValueFields = [indexPatternTimeField].concat(docValueFields);
} else {
docValueFields = [indexPatternTimeField];
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can no longer remember why this block of code was added, but it seems to be causing a regression where the time field value shows up as a multi-value. The effect is even baked into a unit test fixture: https://github.com/elastic/kibana/blob/a8b1a6b/x-pack/test/reporting_api_integration/fixtures.ts#L179

Noticed this while working on: #56371


const searchRequest: SearchRequest = {
index: esIndex,
body: {
Expand Down
Binary file not shown.
Loading