mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Reporting] Correct the docvalue_fields params in the search query Download CSV from Dashboard Panel (#52833) (#53918)
* fix the bug and add a test * fix query bug of empty array Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
f23be0f3ec
commit
c128f93128
8 changed files with 2778 additions and 3 deletions
|
@ -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[];
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
@ -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: {
|
||||
|
|
Binary file not shown.
1226
x-pack/test/functional/es_archives/reporting/ecommerce/mappings.json
Normal file
1226
x-pack/test/functional/es_archives/reporting/ecommerce/mappings.json
Normal file
File diff suppressed because it is too large
Load diff
Binary file not shown.
File diff suppressed because it is too large
Load diff
|
@ -14,6 +14,7 @@ import {
|
|||
CSV_RESULT_TIMEBASED,
|
||||
CSV_RESULT_TIMELESS,
|
||||
CSV_RESULT_NANOS,
|
||||
CSV_RESULT_DOCVALUE,
|
||||
} from './fixtures';
|
||||
|
||||
interface GenerateOpts {
|
||||
|
@ -268,6 +269,68 @@ export default function({ getService }: { getService: any }) {
|
|||
|
||||
await esArchiver.unload('reporting/scripted');
|
||||
});
|
||||
|
||||
it('for docvalue_fields', async () => {
|
||||
// load test data that contains a saved search and documents
|
||||
await esArchiver.load('reporting/ecommerce');
|
||||
await esArchiver.load('reporting/ecommerce_kibana');
|
||||
|
||||
const params = {
|
||||
searchId: 'search:6091ead0-1c6d-11ea-a100-8589bb9d7c6b',
|
||||
postPayload: {
|
||||
timerange: {
|
||||
min: '2019-06-26T06:20:28Z',
|
||||
max: '2019-06-26T07:27:58Z',
|
||||
timezone: 'UTC',
|
||||
},
|
||||
state: {
|
||||
sort: [{ order_date: { order: 'desc', unmapped_type: 'boolean' } }],
|
||||
docvalue_fields: [
|
||||
{ field: 'customer_birth_date', format: 'date_time' },
|
||||
{ field: 'order_date', format: 'date_time' },
|
||||
{ field: 'products.created_on', format: 'date_time' },
|
||||
],
|
||||
query: {
|
||||
bool: {
|
||||
must: [],
|
||||
filter: [
|
||||
{ match_all: {} },
|
||||
{ match_all: {} },
|
||||
{
|
||||
range: {
|
||||
order_date: {
|
||||
gte: '2019-06-26T06:20:28.066Z',
|
||||
lte: '2019-06-26T07:27:58.573Z',
|
||||
format: 'strict_date_optional_time',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
should: [],
|
||||
must_not: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
isImmediate: true,
|
||||
};
|
||||
const {
|
||||
status: resStatus,
|
||||
text: resText,
|
||||
type: resType,
|
||||
} = (await generateAPI.getCsvFromSavedSearch(
|
||||
params.searchId,
|
||||
params.postPayload,
|
||||
params.isImmediate
|
||||
)) as supertest.Response;
|
||||
|
||||
expect(resStatus).to.eql(200);
|
||||
expect(resType).to.eql('text/csv');
|
||||
expect(resText).to.eql(CSV_RESULT_DOCVALUE);
|
||||
|
||||
await esArchiver.unload('reporting/ecommerce');
|
||||
await esArchiver.unload('reporting/ecommerce_kibana');
|
||||
});
|
||||
});
|
||||
|
||||
// FLAKY: https://github.com/elastic/kibana/issues/37471
|
||||
|
|
|
@ -194,3 +194,14 @@ format:strict_date_optional_time,gte:'2004-09-17T21:19:34.213Z',lte:'2019-09-17T
|
|||
213Z')))),must:!(),must_not:!(),should:!())),script_fields:(),sort:!(('@timestamp':(order
|
||||
:desc,unmapped_type:boolean))),stored_fields:!('@timestamp',clientip,extension),version:!
|
||||
t),index:'logstash-*'),title:'A Saved Search With a DATE FILTER',type:search)`;
|
||||
|
||||
export const CSV_RESULT_DOCVALUE = `"order_date",category,currency,"customer_id","order_id","day_of_week_i","order_date","products.created_on",sku
|
||||
"[""2019-06-26T07:26:24.000Z"",""2019-06-26T07:26:24.000Z""]","[""Men\'s Shoes"",""Men\'s Clothing""]",EUR,49,569743,3,"[""2019-06-26T07:26:24.000Z"",""2019-06-26T07:26:24.000Z""]","[""2016-12-15T07:26:24.000Z"",""2016-12-15T07:26:24.000Z""]","[""ZO0403504035"",""ZO0610306103""]"
|
||||
"[""2019-06-26T07:20:38.000Z"",""2019-06-26T07:20:38.000Z""]","[""Men\'s Shoes"",""Women\'s Accessories""]",EUR,29,569736,3,"[""2019-06-26T07:20:38.000Z"",""2019-06-26T07:20:38.000Z""]","[""2016-12-15T07:20:38.000Z"",""2016-12-15T07:20:38.000Z""]","[""ZO0517305173"",""ZO0319703197""]"
|
||||
"[""2019-06-26T07:19:12.000Z"",""2019-06-26T07:19:12.000Z""]","[""Women\'s Clothing"",""Women\'s Shoes""]",EUR,20,569734,3,"[""2019-06-26T07:19:12.000Z"",""2019-06-26T07:19:12.000Z""]","[""2016-12-15T07:19:12.000Z"",""2016-12-15T07:19:12.000Z""]","[""ZO0348703487"",""ZO0141401414""]"
|
||||
"[""2019-06-26T07:00:29.000Z"",""2019-06-26T07:00:29.000Z""]","[""Women\'s Clothing""]",EUR,17,569716,3,"[""2019-06-26T07:00:29.000Z"",""2019-06-26T07:00:29.000Z""]","[""2016-12-15T07:00:29.000Z"",""2016-12-15T07:00:29.000Z""]","[""ZO0146701467"",""ZO0212902129""]"
|
||||
"[""2019-06-26T06:56:10.000Z"",""2019-06-26T06:56:10.000Z""]","[""Women\'s Clothing"",""Women\'s Shoes""]",EUR,6,569710,3,"[""2019-06-26T06:56:10.000Z"",""2019-06-26T06:56:10.000Z""]","[""2016-12-15T06:56:10.000Z"",""2016-12-15T06:56:10.000Z""]","[""ZO0053600536"",""ZO0239702397""]"
|
||||
"[""2019-06-26T06:47:31.000Z"",""2019-06-26T06:47:31.000Z""]","[""Men\'s Shoes""]",EUR,52,569699,3,"[""2019-06-26T06:47:31.000Z"",""2019-06-26T06:47:31.000Z""]","[""2016-12-15T06:47:31.000Z"",""2016-12-15T06:47:31.000Z""]","[""ZO0398603986"",""ZO0521305213""]"
|
||||
"[""2019-06-26T06:37:26.000Z"",""2019-06-26T06:37:26.000Z""]","[""Men\'s Shoes""]",EUR,50,569694,3,"[""2019-06-26T06:37:26.000Z"",""2019-06-26T06:37:26.000Z""]","[""2016-12-15T06:37:26.000Z"",""2016-12-15T06:37:26.000Z""]","[""ZO0398703987"",""ZO0687806878""]"
|
||||
"[""2019-06-26T06:21:36.000Z"",""2019-06-26T06:21:36.000Z""]","[""Men\'s Clothing""]",EUR,52,569679,3,"[""2019-06-26T06:21:36.000Z"",""2019-06-26T06:21:36.000Z""]","[""2016-12-15T06:21:36.000Z"",""2016-12-15T06:21:36.000Z""]","[""ZO0433604336"",""ZO0275702757""]"
|
||||
`;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue