Skip to content

Commit

Permalink
[Reporting] Correct the docvalue_fields params in the search query Do…
Browse files Browse the repository at this point in the history
…wnload CSV from Dashboard Panel (#52833)

* fix the bug and add a test

* fix query bug of empty array

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
tsullivan and elasticmachine authored Jan 2, 2020
1 parent 8c3145e commit 01dd08e
Show file tree
Hide file tree
Showing 8 changed files with 2,778 additions and 3 deletions.
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 },
},
} = 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];
}
}

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

0 comments on commit 01dd08e

Please sign in to comment.