diff --git a/x-pack/plugins/ml/common/types/anomalies.ts b/x-pack/plugins/ml/common/types/anomalies.ts index e84035aa50c8f8..2bf717067f7129 100644 --- a/x-pack/plugins/ml/common/types/anomalies.ts +++ b/x-pack/plugins/ml/common/types/anomalies.ts @@ -12,6 +12,8 @@ export interface Influencer { influencer_field_values: string[]; } +export type MLAnomalyDoc = AnomalyRecordDoc; + export interface AnomalyRecordDoc { [key: string]: any; job_id: string; diff --git a/x-pack/plugins/ml/public/application/explorer/actions/load_explorer_data.ts b/x-pack/plugins/ml/public/application/explorer/actions/load_explorer_data.ts index 621ce442047309..45afab0cce4fd9 100644 --- a/x-pack/plugins/ml/public/application/explorer/actions/load_explorer_data.ts +++ b/x-pack/plugins/ml/public/application/explorer/actions/load_explorer_data.ts @@ -223,7 +223,9 @@ const loadExplorerDataProvider = ( swimlaneLimit, viewByPerPage, viewByFromPage, - swimlaneContainerWidth + swimlaneContainerWidth, + selectionInfluencers, + influencersFilterQuery ) : Promise.resolve([]), }).pipe( diff --git a/x-pack/plugins/ml/public/application/explorer/components/explorer_query_bar/explorer_query_bar.tsx b/x-pack/plugins/ml/public/application/explorer/components/explorer_query_bar/explorer_query_bar.tsx index 6f5ae5e17590ad..57e051e1b8417e 100644 --- a/x-pack/plugins/ml/public/application/explorer/components/explorer_query_bar/explorer_query_bar.tsx +++ b/x-pack/plugins/ml/public/application/explorer/components/explorer_query_bar/explorer_query_bar.tsx @@ -95,7 +95,6 @@ function getInitSearchInputState({ interface ExplorerQueryBarProps { filterActive: boolean; - filterIconTriggeredQuery: string; filterPlaceHolder: string; indexPattern: IIndexPattern; queryString?: string; @@ -104,7 +103,6 @@ interface ExplorerQueryBarProps { export const ExplorerQueryBar: FC = ({ filterActive, - filterIconTriggeredQuery, filterPlaceHolder, indexPattern, queryString, @@ -116,14 +114,12 @@ export const ExplorerQueryBar: FC = ({ ); const [errorMessage, setErrorMessage] = useState(undefined); - useEffect(() => { - if (filterIconTriggeredQuery !== undefined) { - setSearchInput({ - language: searchInput.language, - query: filterIconTriggeredQuery, - }); - } - }, [filterIconTriggeredQuery]); + useEffect( + function updateSearchInputFromFilter() { + setSearchInput(getInitSearchInputState({ filterActive, queryString })); + }, + [filterActive, queryString] + ); const searchChangeHandler = (query: Query) => { if (searchInput.language !== query.language) { @@ -131,6 +127,7 @@ export const ExplorerQueryBar: FC = ({ } setSearchInput(query); }; + const applyInfluencersFilterQuery = (query: Query) => { try { const { clearSettings, settings } = getKqlQueryValues({ diff --git a/x-pack/plugins/ml/public/application/explorer/explorer.js b/x-pack/plugins/ml/public/application/explorer/explorer.js index 142f7bd21726ca..61224414f8310a 100644 --- a/x-pack/plugins/ml/public/application/explorer/explorer.js +++ b/x-pack/plugins/ml/public/application/explorer/explorer.js @@ -86,7 +86,6 @@ const ExplorerPage = ({ filterPlaceHolder, indexPattern, queryString, - filterIconTriggeredQuery, updateLanguage, }) => (
@@ -121,7 +120,6 @@ const ExplorerPage = ({ filterPlaceHolder={filterPlaceHolder} indexPattern={indexPattern} queryString={queryString} - filterIconTriggeredQuery={filterIconTriggeredQuery} updateLanguage={updateLanguage} />
@@ -151,7 +149,7 @@ export class ExplorerUI extends React.Component { selectedJobsRunning: PropTypes.bool.isRequired, }; - state = { filterIconTriggeredQuery: undefined, language: DEFAULT_QUERY_LANG }; + state = { language: DEFAULT_QUERY_LANG }; htmlIdGen = htmlIdGenerator(); componentDidMount() { @@ -200,8 +198,6 @@ export class ExplorerUI extends React.Component { } } - this.setState({ filterIconTriggeredQuery: `${newQueryString}` }); - try { const { clearSettings, settings } = getKqlQueryValues({ inputString: `${newQueryString}`, @@ -331,7 +327,6 @@ export class ExplorerUI extends React.Component { influencers={influencers} filterActive={filterActive} filterPlaceHolder={filterPlaceHolder} - filterIconTriggeredQuery={this.state.filterIconTriggeredQuery} indexPattern={indexPattern} queryString={queryString} updateLanguage={this.updateLanguage} diff --git a/x-pack/plugins/ml/public/application/explorer/explorer_utils.d.ts b/x-pack/plugins/ml/public/application/explorer/explorer_utils.d.ts index ebab308b86027d..e8abe9e45c09ab 100644 --- a/x-pack/plugins/ml/public/application/explorer/explorer_utils.d.ts +++ b/x-pack/plugins/ml/public/application/explorer/explorer_utils.d.ts @@ -181,15 +181,6 @@ declare interface LoadOverallDataResponse { overallSwimlaneData: OverallSwimlaneData; } -export declare const loadViewByTopFieldValuesForSelectedTime: ( - earliestMs: number, - latestMs: number, - selectedJobs: ExplorerJob[], - viewBySwimlaneFieldName: string, - swimlaneLimit: number, - noInfluencersConfigured: boolean -) => Promise; - export declare interface FilterData { influencersFilterQuery: InfluencersFilterQuery; filterActive: boolean; diff --git a/x-pack/plugins/ml/public/application/explorer/swimlane_container.tsx b/x-pack/plugins/ml/public/application/explorer/swimlane_container.tsx index 82f8a90fafb7df..86ec2014c83398 100644 --- a/x-pack/plugins/ml/public/application/explorer/swimlane_container.tsx +++ b/x-pack/plugins/ml/public/application/explorer/swimlane_container.tsx @@ -411,7 +411,7 @@ export const SwimlaneContainer: FC = ({ > <>
-
+
{showSwimlane && !isLoading && ( d.id); @@ -254,7 +258,9 @@ export class AnomalyTimelineService { latestMs, swimlaneLimit, perPage, - fromPage + fromPage, + selectionInfluencers, + influencersFilterQuery ); if (resp.influencers[viewBySwimlaneFieldName] === undefined) { return []; @@ -276,6 +282,8 @@ export class AnomalyTimelineService { earliestMs, latestMs, this.getSwimlaneBucketInterval(selectedJobs, swimlaneContainerWidth).asMilliseconds(), + perPage, + fromPage, swimlaneLimit ); return Object.keys(resp.results); diff --git a/x-pack/plugins/ml/public/application/services/ml_api_service/results.ts b/x-pack/plugins/ml/public/application/services/ml_api_service/results.ts index 25ef36782207f1..a9f6dbb45f6e34 100644 --- a/x-pack/plugins/ml/public/application/services/ml_api_service/results.ts +++ b/x-pack/plugins/ml/public/application/services/ml_api_service/results.ts @@ -16,6 +16,11 @@ import { JobId } from '../../../../common/types/anomaly_detection_jobs'; import { JOB_ID, PARTITION_FIELD_VALUE } from '../../../../common/constants/anomalies'; import { PartitionFieldsDefinition } from '../results_service/result_service_rx'; import { PartitionFieldsConfig } from '../../../../common/types/storage'; +import { + ESSearchRequest, + ESSearchResponse, +} from '../../../../../../../src/core/types/elasticsearch'; +import { MLAnomalyDoc } from '../../../../common/types/anomalies'; export const resultsApiProvider = (httpService: HttpService) => ({ getAnomaliesTableData( @@ -112,18 +117,18 @@ export const resultsApiProvider = (httpService: HttpService) => ({ }); }, - anomalySearch(query: any, jobIds: string[]) { + anomalySearch(query: ESSearchRequest, jobIds: string[]) { const body = JSON.stringify({ query, jobIds }); - return httpService.http({ + return httpService.http>({ path: `${basePath()}/results/anomaly_search`, method: 'POST', body, }); }, - anomalySearch$(query: any, jobIds: string[]) { + anomalySearch$(query: ESSearchRequest, jobIds: string[]) { const body = JSON.stringify({ query, jobIds }); - return httpService.http$({ + return httpService.http$>({ path: `${basePath()}/results/anomaly_search`, method: 'POST', body, diff --git a/x-pack/plugins/ml/public/application/services/results_service/results_service.d.ts b/x-pack/plugins/ml/public/application/services/results_service/results_service.d.ts index ea07d32bfff1d0..1848b13cb5a1f9 100644 --- a/x-pack/plugins/ml/public/application/services/results_service/results_service.d.ts +++ b/x-pack/plugins/ml/public/application/services/results_service/results_service.d.ts @@ -23,7 +23,8 @@ export function resultsServiceProvider( intervalMs: number, perPage?: number, fromPage?: number, - swimLaneSeverity?: number + swimLaneSeverity?: number, + influencersFilterQuery?: InfluencersFilterQuery ): Promise; getTopInfluencers( selectedJobIds: string[], @@ -32,7 +33,7 @@ export function resultsServiceProvider( maxFieldValues: number, perPage?: number, fromPage?: number, - influencers?: any[], + influencers?: EntityField[], influencersFilterQuery?: InfluencersFilterQuery ): Promise; getTopInfluencerValues(): Promise;