Skip to content

Commit

Permalink
[Data] Pass field meta to value suggestions api (#96239) (#96922)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Shahzad <[email protected]>
  • Loading branch information
kibanamachine and shahzad31 authored Apr 13, 2021
1 parent cebb0ae commit f422168
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const setupValueSuggestionProvider = (
return core.http
.fetch(`/api/kibana/suggestions/values/${index}`, {
method: 'POST',
body: JSON.stringify({ query, field: field.name, filters }),
body: JSON.stringify({ query, field: field.name, fieldMeta: field?.toSpec?.(), filters }),
signal,
})
.then((r) => {
Expand Down
12 changes: 9 additions & 3 deletions src/plugins/data/server/autocomplete/value_suggestions_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ export function registerValueSuggestionsRoute(
field: schema.string(),
query: schema.string(),
filters: schema.maybe(schema.any()),
fieldMeta: schema.maybe(schema.any()),
},
{ unknowns: 'allow' }
),
},
},
async (context, request, response) => {
const config = await config$.pipe(first()).toPromise();
const { field: fieldName, query, filters } = request.body;
const { field: fieldName, query, filters, fieldMeta } = request.body;
const { index } = request.params;
const { client } = context.core.elasticsearch.legacy;
const signal = getRequestAbortedSignal(request.events.aborted$);
Expand All @@ -53,9 +54,14 @@ export function registerValueSuggestionsRoute(
terminate_after: config.kibana.autocompleteTerminateAfter.asMilliseconds(),
};

const indexPattern = await findIndexPatternById(context.core.savedObjects.client, index);
let field: IFieldType | undefined = fieldMeta;

if (!field?.name && !field?.type) {
const indexPattern = await findIndexPatternById(context.core.savedObjects.client, index);

field = indexPattern && getFieldByName(fieldName, indexPattern);
}

const field = indexPattern && getFieldByName(fieldName, indexPattern);
const body = await getBody(autocompleteSearchOptions, field || fieldName, query, filters);

const result = await client.callAsCurrentUser('search', { index, body }, { signal });
Expand Down

0 comments on commit f422168

Please sign in to comment.