Skip to content

Commit

Permalink
[ML] result_type term based on model plot config
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Jan 6, 2020
1 parent d7b90d7 commit 72fb707
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import Boom from 'boom';
import _ from 'lodash';
import moment from 'moment';

Expand Down Expand Up @@ -476,6 +477,15 @@ export function resultsServiceProvider(callWithRequest) {
earliestMs,
latestMs
) {
const jobsResponse = await callWithRequest('ml.jobs', { jobId: [jobId] });
if (jobsResponse.count === 0 || jobsResponse.jobs === undefined) {
throw Boom.notFound(`Job with the id "${jobId}" not found`);
}

const job = jobsResponse.jobs[0];
// eslint-disable-next-line camelcase
const isModelPlotEnabled = job?.model_plot_config?.enabled;

const fields = ['partition_field', 'over_field', 'by_field'];

const resp = await callWithRequest('search', {
Expand Down Expand Up @@ -506,6 +516,11 @@ export function resultsServiceProvider(callWithRequest) {
},
},
},
{
term: {
result_type: isModelPlotEnabled ? 'model_plot' : 'record',
},
},
],
},
},
Expand Down

0 comments on commit 72fb707

Please sign in to comment.