Skip to content

Commit

Permalink
[ML] Add support for fields in getFieldExamples
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Jan 26, 2021
1 parent dd5ed19 commit d44517f
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions x-pack/plugins/ml/server/models/data_visualizer/data_visualizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,8 @@ export class DataVisualizer {
});

const searchBody = {
_source: field,
fields: [field],
_source: false,
query: {
bool: {
filter: filterCriteria,
Expand All @@ -1209,16 +1210,16 @@ export class DataVisualizer {
if (body.hits.total.value > 0) {
const hits = body.hits.hits;
for (let i = 0; i < hits.length; i++) {
// Look in the _source for the field value.
// If the field is not in the _source (as will happen if the
// field is populated using copy_to in the index mapping),
// there will be no example to add.
// Use lodash get() to support field names containing dots.
const example: any = get(hits[i]._source, field);
if (example !== undefined && stats.examples.indexOf(example) === -1) {
stats.examples.push(example);
if (stats.examples.length === maxExamples) {
break;
const doc: any = get(hits[i].fields, field);
// the results from fields query is always an array
if (Array.isArray(doc) && doc.length > 0) {
const example = doc[0];
if (example !== undefined && stats.examples.indexOf(example) === -1) {
stats.examples.push(example);
if (stats.examples.length === maxExamples) {
break;
}
}
}
}
Expand Down

0 comments on commit d44517f

Please sign in to comment.