Skip to content

Commit 01dd08e

Browse files
[Reporting] Correct the docvalue_fields params in the search query Download CSV from Dashboard Panel (#52833)
* fix the bug and add a test * fix query bug of empty array Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 8c3145e commit 01dd08e

File tree

8 files changed

+2778
-3
lines changed

8 files changed

+2778
-3
lines changed

x-pack/legacy/plugins/reporting/export_types/csv/types.d.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@
66

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

9+
interface DocValueField {
10+
field: string;
11+
format: string;
12+
}
13+
14+
interface SortOptions {
15+
order: string;
16+
unmapped_type: string;
17+
}
18+
919
export interface JobParamPostPayloadDiscoverCsv extends JobParamPostPayload {
1020
state?: {
1121
query: any;
12-
sort: any[];
22+
sort: Array<Record<string, SortOptions>>;
23+
docvalue_fields: DocValueField[];
1324
};
1425
}
1526

x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/generate_csv_search.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ export async function generateCsvSearch(
8484

8585
let payloadQuery: QueryFilter | undefined;
8686
let payloadSort: any[] = [];
87+
let docValueFields: any[] | undefined;
8788
if (jobParams.post && jobParams.post.state) {
8889
({
8990
post: {
90-
state: { query: payloadQuery, sort: payloadSort = [] },
91+
state: { query: payloadQuery, sort: payloadSort = [], docvalue_fields: docValueFields },
9192
},
9293
} = jobParams);
9394
}
@@ -119,7 +120,15 @@ export async function generateCsvSearch(
119120
},
120121
};
121122
}, {});
122-
const docValueFields = indexPatternTimeField ? [indexPatternTimeField] : undefined;
123+
124+
if (indexPatternTimeField) {
125+
if (docValueFields) {
126+
docValueFields = [indexPatternTimeField].concat(docValueFields);
127+
} else {
128+
docValueFields = [indexPatternTimeField];
129+
}
130+
}
131+
123132
const searchRequest: SearchRequest = {
124133
index: esIndex,
125134
body: {
Binary file not shown.

0 commit comments

Comments
 (0)