Skip to content

Commit

Permalink
[ML] Add rest_total_hit_as_int where total hits is required (elastic#…
Browse files Browse the repository at this point in the history
  • Loading branch information
peteharverson committed Dec 4, 2018
1 parent cd3f25d commit 8186bd9
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ function getSearchJsonFromConfig(formConfig) {
const json = {
index: formConfig.indexPattern.title,
size: 0,
rest_total_hits_as_int: true,
body: {
query: {},
aggs: {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/ml/public/services/forecast_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function getForecastsSummary(
ml.esSearch({
index: ML_RESULTS_INDEX_PATTERN,
size: maxResults,
rest_total_hits_as_int: true,
body: {
query: {
bool: {
Expand Down Expand Up @@ -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: {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/ml/public/services/job_messages_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
{
Expand Down Expand Up @@ -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: {
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/ml/public/services/results_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -1351,6 +1355,7 @@ function getEventRateData(

ml.esSearch({
index,
rest_total_hits_as_int: true,
size: 0,
body: {
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
13 changes: 11 additions & 2 deletions x-pack/plugins/ml/server/models/data_visualizer/data_visualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
{
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 8186bd9

Please sign in to comment.