From c24bc710c170acfb894efa4b2d1fb382412271a5 Mon Sep 17 00:00:00 2001 From: Wylie Conlon Date: Tue, 14 Jan 2020 15:08:38 -0500 Subject: [PATCH] [Lens] Show fields when using indexpattern without time field --- .../lens/server/routes/existing_fields.ts | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/x-pack/legacy/plugins/lens/server/routes/existing_fields.ts b/x-pack/legacy/plugins/lens/server/routes/existing_fields.ts index 55f8fd3b1a72bf..fbbcf9973431b8 100644 --- a/x-pack/legacy/plugins/lens/server/routes/existing_fields.ts +++ b/x-pack/legacy/plugins/lens/server/routes/existing_fields.ts @@ -204,8 +204,27 @@ async function fetchIndexPatternStats({ toDate?: string; fields: Field[]; }) { - if (!timeFieldName || !fromDate || !toDate) { - return []; + let query; + + if (timeFieldName && fromDate && toDate) { + query = { + bool: { + filter: [ + { + range: { + [timeFieldName]: { + gte: fromDate, + lte: toDate, + }, + }, + }, + ], + }, + }; + } else { + query = { + match_all: {}, + }; } const viableFields = fields.filter( f => !f.isScript && !f.isAlias && !metaFields.includes(f.name) @@ -217,20 +236,7 @@ async function fetchIndexPatternStats({ body: { size: SAMPLE_SIZE, _source: viableFields.map(f => f.name), - query: { - bool: { - filter: [ - { - range: { - [timeFieldName]: { - gte: fromDate, - lte: toDate, - }, - }, - }, - ], - }, - }, + query, script_fields: scriptedFields.reduce((acc, field) => { acc[field.name] = { script: {