Skip to content

Commit

Permalink
[ML] DataFrame Analytics: filter out docs with no prediction data fro…
Browse files Browse the repository at this point in the history
…m results table (#54826) (#55078)

* filter out docs with no prediction data from results table

* ensure bool.must exists in the cloned searchQuery

* create must in bool query if not present
  • Loading branch information
alvarezmelissa87 committed Jan 16, 2020
1 parent 5f2f073 commit 742fb0e
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ import { ExplorationTitle } from './classification_exploration';
const PAGE_SIZE_OPTIONS = [5, 10, 25, 50];

const MlInMemoryTableBasic = mlInMemoryTableBasicFactory<TableItem>();

const showingDocs = i18n.translate(
'xpack.ml.dataframe.analytics.classificationExploration.documentsShownHelpText',
{
defaultMessage: 'Showing documents for which predictions exist',
}
);

const showingFirstDocs = i18n.translate(
'xpack.ml.dataframe.analytics.classificationExploration.firstDocumentsShownHelpText',
{
defaultMessage: 'Showing first {searchSize} documents for which predictions exist',
values: { searchSize: SEARCH_SIZE },
}
);

interface Props {
jobConfig: DataFrameAnalyticsConfig;
jobStatus: DATA_FRAME_TASK_STATE;
Expand Down Expand Up @@ -468,19 +484,11 @@ export const ResultsTable: FC<Props> = React.memo(
)}
{(columns.length > 0 || searchQuery !== defaultSearchQuery) && (
<Fragment>
{tableItems.length === SEARCH_SIZE && (
<EuiFormRow
helpText={i18n.translate(
'xpack.ml.dataframe.analytics.classificationExploration.documentsShownHelpText',
{
defaultMessage: 'Showing first {searchSize} documents',
values: { searchSize: SEARCH_SIZE },
}
)}
>
<Fragment />
</EuiFormRow>
)}
<EuiFormRow
helpText={tableItems.length === SEARCH_SIZE ? showingFirstDocs : showingDocs}
>
<Fragment />
</EuiFormRow>
<EuiSpacer />
<MlInMemoryTableBasic
allowNeutralSort={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@
import React, { useEffect, useState } from 'react';

import { SearchResponse } from 'elasticsearch';
import { cloneDeep } from 'lodash';

import { SortDirection, SORT_DIRECTION } from '../../../../../components/ml_in_memory_table';

import { ml } from '../../../../../services/ml_api_service';
import { getNestedProperty } from '../../../../../util/object_utils';
import { newJobCapsService } from '../../../../../services/new_job_capabilities_service';
import { Field } from '../../../../../../../common/types/fields';
import { LoadExploreDataArg } from '../../../../common/analytics';
import { ES_FIELD_TYPES } from '../../../../../../../../../../../src/plugins/data/public';
import {
LoadExploreDataArg,
defaultSearchQuery,
ResultsSearchQuery,
isResultsSearchBoolQuery,
} from '../../../../common/analytics';

import {
getDefaultFieldsFromJobCaps,
Expand Down Expand Up @@ -84,8 +90,33 @@ export const useExploreData = (

try {
const resultsField = jobConfig.dest.results_field;
const searchQueryClone: ResultsSearchQuery = cloneDeep(searchQuery);
let query: ResultsSearchQuery;

if (JSON.stringify(searchQuery) === JSON.stringify(defaultSearchQuery)) {
query = {
exists: {
field: resultsField,
},
};
} else if (isResultsSearchBoolQuery(searchQueryClone)) {
if (searchQueryClone.bool.must === undefined) {
searchQueryClone.bool.must = [];
}

searchQueryClone.bool.must.push({
exists: {
field: resultsField,
},
});

query = searchQueryClone;
} else {
query = searchQueryClone;
}

const body: SearchQuery = {
query: searchQuery,
query,
};

if (field !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ const PAGE_SIZE_OPTIONS = [5, 10, 25, 50];

const MlInMemoryTableBasic = mlInMemoryTableBasicFactory<TableItem>();

const showingDocs = i18n.translate(
'xpack.ml.dataframe.analytics.regressionExploration.documentsShownHelpText',
{
defaultMessage: 'Showing documents for which predictions exist',
}
);

const showingFirstDocs = i18n.translate(
'xpack.ml.dataframe.analytics.regressionExploration.firstDocumentsShownHelpText',
{
defaultMessage: 'Showing first {searchSize} documents for which predictions exist',
values: { searchSize: SEARCH_SIZE },
}
);

interface Props {
jobConfig: DataFrameAnalyticsConfig;
jobStatus: DATA_FRAME_TASK_STATE;
Expand Down Expand Up @@ -468,19 +483,12 @@ export const ResultsTable: FC<Props> = React.memo(
)}
{(columns.length > 0 || searchQuery !== defaultSearchQuery) && (
<Fragment>
{tableItems.length === SEARCH_SIZE && (
<EuiFormRow
helpText={i18n.translate(
'xpack.ml.dataframe.analytics.regressionExploration.documentsShownHelpText',
{
defaultMessage: 'Showing first {searchSize} documents',
values: { searchSize: SEARCH_SIZE },
}
)}
>
<Fragment />
</EuiFormRow>
)}
<EuiFormRow
helpText={tableItems.length === SEARCH_SIZE ? showingFirstDocs : showingDocs}
>
<Fragment />
</EuiFormRow>

<EuiSpacer />
<MlInMemoryTableBasic
allowNeutralSort={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import React, { useEffect, useState } from 'react';

import { SearchResponse } from 'elasticsearch';
import { cloneDeep } from 'lodash';

import { SortDirection, SORT_DIRECTION } from '../../../../../components/ml_in_memory_table';

Expand All @@ -24,8 +25,13 @@ import {
SearchQuery,
} from '../../../../common';
import { Field } from '../../../../../../../common/types/fields';
import { LoadExploreDataArg } from '../../../../common/analytics';
import { ES_FIELD_TYPES } from '../../../../../../../../../../../src/plugins/data/public';
import {
LoadExploreDataArg,
defaultSearchQuery,
ResultsSearchQuery,
isResultsSearchBoolQuery,
} from '../../../../common/analytics';

export type TableItem = Record<string, any>;

Expand Down Expand Up @@ -79,8 +85,32 @@ export const useExploreData = (

try {
const resultsField = jobConfig.dest.results_field;
const searchQueryClone: ResultsSearchQuery = cloneDeep(searchQuery);
let query: ResultsSearchQuery;

if (JSON.stringify(searchQuery) === JSON.stringify(defaultSearchQuery)) {
query = {
exists: {
field: resultsField,
},
};
} else if (isResultsSearchBoolQuery(searchQueryClone)) {
if (searchQueryClone.bool.must === undefined) {
searchQueryClone.bool.must = [];
}

searchQueryClone.bool.must.push({
exists: {
field: resultsField,
},
});

query = searchQueryClone;
} else {
query = searchQueryClone;
}
const body: SearchQuery = {
query: searchQuery,
query,
};

if (field !== undefined) {
Expand Down

0 comments on commit 742fb0e

Please sign in to comment.