[data views] composite runtime fields in api layer (#125183)

* composite runtime fields in data view layer
This commit is contained in:
Matthew Kime 2022-02-23 19:11:32 -06:00 committed by GitHub
parent 2aafd3be99
commit ffe964f119
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 736 additions and 218 deletions

View file

@ -173,6 +173,8 @@ async function legacyFetchFieldExistenceSampling({
const indexPattern = await dataViewsService.get(indexPatternId);
const fields = buildFieldList(indexPattern, metaFields);
const runtimeMappings = indexPattern.getRuntimeMappings();
const docs = await fetchIndexPatternStats({
fromDate,
toDate,
@ -181,6 +183,7 @@ async function legacyFetchFieldExistenceSampling({
index: indexPattern.title,
timeFieldName: timeFieldName || indexPattern.timeFieldName,
fields,
runtimeMappings,
includeFrozen,
});
@ -216,6 +219,7 @@ async function fetchIndexPatternStats({
fromDate,
toDate,
fields,
runtimeMappings,
includeFrozen,
}: {
client: ElasticsearchClient;
@ -225,12 +229,12 @@ async function fetchIndexPatternStats({
fromDate?: string;
toDate?: string;
fields: Field[];
runtimeMappings: estypes.MappingRuntimeFields;
includeFrozen: boolean;
}) {
const query = toQuery(timeFieldName, fromDate, toDate, dslQuery);
const scriptedFields = fields.filter((f) => f.isScript);
const runtimeFields = fields.filter((f) => f.runtimeField);
const result = await client.search(
{
index,
@ -242,11 +246,7 @@ async function fetchIndexPatternStats({
sort: timeFieldName && fromDate && toDate ? [{ [timeFieldName]: 'desc' }] : [],
fields: ['*'],
_source: false,
runtime_mappings: runtimeFields.reduce((acc, field) => {
if (!field.runtimeField) return acc;
acc[field.name] = field.runtimeField;
return acc;
}, {} as Record<string, estypes.MappingRuntimeField>),
runtime_mappings: runtimeMappings,
script_fields: scriptedFields.reduce((acc, field) => {
acc[field.name] = {
script: {

View file

@ -84,6 +84,7 @@ export async function initFieldsRoute(setup: CoreSetup<PluginStartContract>) {
.filter((f) => f.runtimeField)
.reduce((acc, f) => {
if (!f.runtimeField) return acc;
// @ts-expect-error The MappingRuntimeField from @elastic/elasticsearch does not expose the "composite" runtime type yet
acc[f.name] = f.runtimeField;
return acc;
}, {} as Record<string, estypes.MappingRuntimeField>);