From 2b53056651b60271e9cccffd6459086e3dce26c1 Mon Sep 17 00:00:00 2001 From: Pete Harverson Date: Tue, 4 Dec 2018 10:16:57 +0000 Subject: [PATCH] [ML] Add rest_total_hit_as_int where total hits is required (#26421) (#26613) --- .../jobs/components/custom_url_editor/utils.js | 1 + .../single_metric/create_job/create_job_service.js | 1 + .../plugins/ml/public/services/forecast_service.js | 2 ++ .../ml/public/services/job_messages_service.js | 2 ++ .../plugins/ml/public/services/results_service.js | 5 +++++ .../models/data_recognizer/data_recognizer.js | 7 ++++++- .../models/data_visualizer/data_visualizer.js | 13 +++++++++++-- .../models/job_audit_messages/job_audit_messages.js | 2 ++ .../models/results_service/results_service.js | 3 +++ 9 files changed, 33 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/ml/public/jobs/components/custom_url_editor/utils.js b/x-pack/plugins/ml/public/jobs/components/custom_url_editor/utils.js index 09505e77dc0c..08766835c73b 100644 --- a/x-pack/plugins/ml/public/jobs/components/custom_url_editor/utils.js +++ b/x-pack/plugins/ml/public/jobs/components/custom_url_editor/utils.js @@ -319,6 +319,7 @@ export function getTestUrl(job, customUrl) { return new Promise((resolve, reject) => { ml.esSearch({ index: ML_RESULTS_INDEX_PATTERN, + rest_total_hits_as_int: true, body }) .then((resp) => { diff --git a/x-pack/plugins/ml/public/jobs/new_job/simple/single_metric/create_job/create_job_service.js b/x-pack/plugins/ml/public/jobs/new_job/simple/single_metric/create_job/create_job_service.js index 37d7ac1ebbd8..d7b6fb5cac16 100644 --- a/x-pack/plugins/ml/public/jobs/new_job/simple/single_metric/create_job/create_job_service.js +++ b/x-pack/plugins/ml/public/jobs/new_job/simple/single_metric/create_job/create_job_service.js @@ -430,6 +430,7 @@ function getSearchJsonFromConfig(formConfig) { const json = { index: formConfig.indexPattern.title, size: 0, + rest_total_hits_as_int: true, body: { query: {}, aggs: { diff --git a/x-pack/plugins/ml/public/services/forecast_service.js b/x-pack/plugins/ml/public/services/forecast_service.js index 09a6b03f4658..17b29e65cfde 100644 --- a/x-pack/plugins/ml/public/services/forecast_service.js +++ b/x-pack/plugins/ml/public/services/forecast_service.js @@ -59,6 +59,7 @@ function getForecastsSummary( ml.esSearch({ index: ML_RESULTS_INDEX_PATTERN, size: maxResults, + rest_total_hits_as_int: true, body: { query: { bool: { @@ -352,6 +353,7 @@ function getForecastRequestStats(job, forecastId) { ml.esSearch({ index: ML_RESULTS_INDEX_PATTERN, size: 1, + rest_total_hits_as_int: true, body: { query: { bool: { diff --git a/x-pack/plugins/ml/public/services/job_messages_service.js b/x-pack/plugins/ml/public/services/job_messages_service.js index dd2481886d4f..71ad13bf0d4f 100644 --- a/x-pack/plugins/ml/public/services/job_messages_service.js +++ b/x-pack/plugins/ml/public/services/job_messages_service.js @@ -54,6 +54,7 @@ function getJobAuditMessages(fromRange, jobId) { ml.esSearch({ index: ML_NOTIFICATION_INDEX_PATTERN, ignore_unavailable: true, + rest_total_hits_as_int: true, size: 1000, body: { @@ -99,6 +100,7 @@ function getAuditMessagesSummary() { ml.esSearch({ index: ML_NOTIFICATION_INDEX_PATTERN, ignore_unavailable: true, + rest_total_hits_as_int: true, size: 0, body: { query: { diff --git a/x-pack/plugins/ml/public/services/results_service.js b/x-pack/plugins/ml/public/services/results_service.js index 9c9f4906340b..b4bf711a86de 100644 --- a/x-pack/plugins/ml/public/services/results_service.js +++ b/x-pack/plugins/ml/public/services/results_service.js @@ -765,6 +765,7 @@ function getRecordInfluencers(jobIds, threshold, earliestMs, latestMs, maxResult ml.esSearch({ index: ML_RESULTS_INDEX_PATTERN, size: maxResults !== undefined ? maxResults : 100, + rest_total_hits_as_int: true, body: { _source: ['job_id', 'detector_index', 'influencers', 'record_score'], query: { @@ -887,6 +888,7 @@ function getRecordsForInfluencer(jobIds, influencers, threshold, earliestMs, lat ml.esSearch({ index: ML_RESULTS_INDEX_PATTERN, size: maxResults !== undefined ? maxResults : 100, + rest_total_hits_as_int: true, body: { query: { bool: { @@ -1013,6 +1015,7 @@ function getRecordsForDetector( ml.esSearch({ index: ML_RESULTS_INDEX_PATTERN, size: maxResults !== undefined ? maxResults : 100, + rest_total_hits_as_int: true, body: { query: { bool: { @@ -1116,6 +1119,7 @@ function getRecordsForCriteria(jobIds, criteriaFields, threshold, earliestMs, la ml.esSearch({ index: ML_RESULTS_INDEX_PATTERN, + rest_total_hits_as_int: true, size: maxResults !== undefined ? maxResults : 100, body: { query: { @@ -1351,6 +1355,7 @@ function getEventRateData( ml.esSearch({ index, + rest_total_hits_as_int: true, size: 0, body: { query: { diff --git a/x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.js b/x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.js index 34f4daddba65..1776d0e0042b 100644 --- a/x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.js +++ b/x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.js @@ -115,7 +115,12 @@ export class DataRecognizer { query: moduleConfig.query }; - const resp = await this.callWithRequest('search', { index, size, body }); + const resp = await this.callWithRequest('search', { + index, + rest_total_hits_as_int: true, + size, + body + }); return (resp.hits.total !== 0); } diff --git a/x-pack/plugins/ml/server/models/data_visualizer/data_visualizer.js b/x-pack/plugins/ml/server/models/data_visualizer/data_visualizer.js index 0750571aa4b0..d98eb1ab21a8 100644 --- a/x-pack/plugins/ml/server/models/data_visualizer/data_visualizer.js +++ b/x-pack/plugins/ml/server/models/data_visualizer/data_visualizer.js @@ -319,7 +319,11 @@ export class DataVisualizer { }; filterCriteria.push({ exists: { field } }); - const resp = await this.callWithRequest('search', { index, size, body }); + const resp = await this.callWithRequest('search', { + index, + rest_total_hits_as_int: true, + size, + body }); return (resp.hits.total > 0); } @@ -710,7 +714,12 @@ export class DataVisualizer { } }; - const resp = await this.callWithRequest('search', { index, size, body }); + const resp = await this.callWithRequest('search', { + index, + rest_total_hits_as_int: true, + size, + body + }); const stats = { fieldName: field, examples: [] diff --git a/x-pack/plugins/ml/server/models/job_audit_messages/job_audit_messages.js b/x-pack/plugins/ml/server/models/job_audit_messages/job_audit_messages.js index 3a6a61474f8d..f6bab3c7a137 100644 --- a/x-pack/plugins/ml/server/models/job_audit_messages/job_audit_messages.js +++ b/x-pack/plugins/ml/server/models/job_audit_messages/job_audit_messages.js @@ -80,6 +80,7 @@ export function jobAuditMessagesProvider(callWithRequest) { const resp = await callWithRequest('search', { index: ML_NOTIFICATION_INDEX_PATTERN, ignore_unavailable: true, + rest_total_hits_as_int: true, size: SIZE, body: { @@ -107,6 +108,7 @@ export function jobAuditMessagesProvider(callWithRequest) { const resp = await callWithRequest('search', { index: ML_NOTIFICATION_INDEX_PATTERN, ignore_unavailable: true, + rest_total_hits_as_int: true, size: 0, body: { query: { diff --git a/x-pack/plugins/ml/server/models/results_service/results_service.js b/x-pack/plugins/ml/server/models/results_service/results_service.js index 34191dd2aa67..3c33979a9ad1 100644 --- a/x-pack/plugins/ml/server/models/results_service/results_service.js +++ b/x-pack/plugins/ml/server/models/results_service/results_service.js @@ -120,6 +120,7 @@ export function resultsServiceProvider(callWithRequest) { const resp = await callWithRequest('search', { index: ML_RESULTS_INDEX_PATTERN, + rest_total_hits_as_int: true, size: maxRecords, body: { query: { @@ -201,6 +202,7 @@ export function resultsServiceProvider(callWithRequest) { async function getCategoryExamples(jobId, categoryIds, maxExamples) { const resp = await callWithRequest('search', { index: ML_RESULTS_INDEX_PATTERN, + rest_total_hits_as_int: true, size: DEFAULT_QUERY_SIZE, // Matches size of records in anomaly summary table. body: { query: { @@ -235,6 +237,7 @@ export function resultsServiceProvider(callWithRequest) { async function getCategoryDefinition(jobId, categoryId) { const resp = await callWithRequest('search', { index: ML_RESULTS_INDEX_PATTERN, + rest_total_hits_as_int: true, size: 1, body: { query: {