Skip to content

Commit

Permalink
using isPopulatedObject
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Mar 16, 2021
1 parent feb5443 commit 8ca21bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 6 additions & 5 deletions x-pack/plugins/ml/server/models/job_service/datafeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ML_DATA_PREVIEW_COUNT } from '../../../common/util/job_utils';
import { fieldsServiceProvider } from '../fields_service';
import type { MlClient } from '../../lib/ml_client';
import { parseInterval } from '../../../common/util/parse_interval';
import { isPopulatedObject } from '../../../common/util/object_utils';

export interface MlDatafeedsResponse {
datafeeds: Datafeed[];
Expand Down Expand Up @@ -260,19 +261,19 @@ export function datafeedsProvider(client: IScopedClusterClient, mlClient: MlClie

// if aggs or aggregations is set, add it to the search
const aggregations = datafeed.aggs ?? datafeed.aggregations;
if (aggregations && Object.keys(aggregations).length) {
if (isPopulatedObject(aggregations)) {
body.size = 0;
body.aggregations = aggregations;

// add script_fields if present
const scriptFields = datafeed.script_fields;
if (scriptFields && Object.keys(scriptFields).length) {
if (isPopulatedObject(scriptFields)) {
body.script_fields = scriptFields;
}

// add runtime_mappings if present
const runtimeMappings = datafeed.runtime_mappings;
if (runtimeMappings && Object.keys(runtimeMappings).length) {
if (isPopulatedObject(runtimeMappings)) {
body.runtime_mappings = runtimeMappings;
}
} else {
Expand All @@ -281,13 +282,13 @@ export function datafeedsProvider(client: IScopedClusterClient, mlClient: MlClie

// add script_fields if present
const scriptFields = datafeed.script_fields;
if (scriptFields && Object.keys(scriptFields).length) {
if (isPopulatedObject(scriptFields)) {
body.script_fields = scriptFields;
}

// add runtime_mappings if present
const runtimeMappings = datafeed.runtime_mappings;
if (runtimeMappings && Object.keys(runtimeMappings).length) {
if (isPopulatedObject(runtimeMappings)) {
body.runtime_mappings = runtimeMappings;
}

Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/ml/server/routes/job_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ export function jobServiceRoutes({ router, routeGuard }: RouteInitialization) {
splitFieldName,
splitFieldValue,
runtimeMappings,

indicesOptions
);

Expand Down Expand Up @@ -610,7 +609,6 @@ export function jobServiceRoutes({ router, routeGuard }: RouteInitialization) {
aggFieldNamePairs,
splitFieldName,
runtimeMappings,

indicesOptions
);

Expand Down

0 comments on commit 8ca21bb

Please sign in to comment.