-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] Fix new job with must_not saved search #71831
Merged
jgowdyelastic
merged 5 commits into
elastic:master
from
jgowdyelastic:fix-new-job-with-must_not-saved-search
Jul 15, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
872364d
[ML] Fix new job with must_not saved search
jgowdyelastic a04fdfd
adding tests
jgowdyelastic 280562d
Merge branch 'master' into fix-new-job-with-must_not-saved-search
elasticmachine 41db653
initialising saved search in beforeEach
jgowdyelastic d6294e2
another commit for odd github issues
jgowdyelastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
209 changes: 209 additions & 0 deletions
209
x-pack/plugins/ml/public/application/jobs/new_job/utils/new_job_utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { IUiSettingsClient } from 'kibana/public'; | ||
import { IIndexPattern } from '../../../../../../../../src/plugins/data/common/index_patterns'; | ||
import { SavedSearchSavedObject } from '../../../../../common/types/kibana'; | ||
import { createSearchItems } from './new_job_utils'; | ||
|
||
describe('createSearchItems', () => { | ||
const kibanaConfig = {} as IUiSettingsClient; | ||
const indexPattern = ({ | ||
fields: [], | ||
} as unknown) as IIndexPattern; | ||
|
||
let savedSearch = ({} as unknown) as SavedSearchSavedObject; | ||
beforeEach(() => { | ||
savedSearch = ({ | ||
client: { | ||
http: { | ||
basePath: { | ||
basePath: '/abc', | ||
serverBasePath: '/abc', | ||
}, | ||
anonymousPaths: {}, | ||
}, | ||
batchQueue: [], | ||
}, | ||
attributes: { | ||
title: 'not test', | ||
description: '', | ||
hits: 0, | ||
columns: ['_source'], | ||
sort: [], | ||
version: 1, | ||
kibanaSavedObjectMeta: { | ||
searchSourceJSON: '', | ||
}, | ||
}, | ||
_version: 'WzI0OSw0XQ==', | ||
id: '4b9b1010-c678-11ea-b6e6-e942978da29c', | ||
type: 'search', | ||
migrationVersion: { | ||
search: '7.4.0', | ||
}, | ||
references: [ | ||
{ | ||
name: 'kibanaSavedObjectMeta.searchSourceJSON.index', | ||
type: 'index-pattern', | ||
id: '7e252840-bd27-11ea-8a6c-75d1a0bd08ab', | ||
}, | ||
], | ||
} as unknown) as SavedSearchSavedObject; | ||
}); | ||
|
||
test('should match index pattern', () => { | ||
const resp = createSearchItems(kibanaConfig, indexPattern, null); | ||
expect(resp).toStrictEqual({ | ||
combinedQuery: { bool: { must: [{ match_all: {} }] } }, | ||
query: { query: '', language: 'lucene' }, | ||
}); | ||
}); | ||
|
||
test('should match saved search with kuery and condition', () => { | ||
const searchSource = { | ||
highlightAll: true, | ||
version: true, | ||
query: { query: 'airline : "AAL" ', language: 'kuery' }, | ||
filter: [], | ||
indexRefName: 'kibanaSavedObjectMeta.searchSourceJSON.index', | ||
}; | ||
savedSearch.attributes.kibanaSavedObjectMeta.searchSourceJSON = JSON.stringify(searchSource); | ||
|
||
const resp = createSearchItems(kibanaConfig, indexPattern, savedSearch); | ||
expect(resp).toStrictEqual({ | ||
combinedQuery: { | ||
bool: { | ||
should: [{ match_phrase: { airline: 'AAL' } }], | ||
minimum_should_match: 1, | ||
filter: [], | ||
must_not: [], | ||
}, | ||
}, | ||
query: { | ||
language: 'kuery', | ||
query: 'airline : "AAL" ', | ||
}, | ||
}); | ||
}); | ||
|
||
test('should match saved search with kuery and not condition', () => { | ||
const searchSource = { | ||
highlightAll: true, | ||
version: true, | ||
query: { query: 'NOT airline : "AAL" ', language: 'kuery' }, | ||
filter: [], | ||
indexRefName: 'kibanaSavedObjectMeta.searchSourceJSON.index', | ||
}; | ||
savedSearch.attributes.kibanaSavedObjectMeta.searchSourceJSON = JSON.stringify(searchSource); | ||
|
||
const resp = createSearchItems(kibanaConfig, indexPattern, savedSearch); | ||
expect(resp).toStrictEqual({ | ||
combinedQuery: { | ||
bool: { | ||
filter: [], | ||
must_not: [ | ||
{ | ||
bool: { | ||
minimum_should_match: 1, | ||
should: [ | ||
{ | ||
match_phrase: { | ||
airline: 'AAL', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
query: { | ||
language: 'kuery', | ||
query: 'NOT airline : "AAL" ', | ||
}, | ||
}); | ||
}); | ||
|
||
test('should match saved search with kuery and condition and not condition', () => { | ||
const searchSource = { | ||
highlightAll: true, | ||
version: true, | ||
query: { query: 'airline : "AAL" and NOT airline : "AWE" ', language: 'kuery' }, | ||
filter: [], | ||
indexRefName: 'kibanaSavedObjectMeta.searchSourceJSON.index', | ||
}; | ||
savedSearch.attributes.kibanaSavedObjectMeta.searchSourceJSON = JSON.stringify(searchSource); | ||
|
||
const resp = createSearchItems(kibanaConfig, indexPattern, savedSearch); | ||
expect(resp).toStrictEqual({ | ||
combinedQuery: { | ||
bool: { | ||
filter: [ | ||
{ bool: { should: [{ match_phrase: { airline: 'AAL' } }], minimum_should_match: 1 } }, | ||
{ | ||
bool: { | ||
must_not: { | ||
bool: { should: [{ match_phrase: { airline: 'AWE' } }], minimum_should_match: 1 }, | ||
}, | ||
}, | ||
}, | ||
], | ||
must_not: [], | ||
}, | ||
}, | ||
query: { query: 'airline : "AAL" and NOT airline : "AWE" ', language: 'kuery' }, | ||
}); | ||
}); | ||
|
||
test('should match saved search with kuery and filter', () => { | ||
const searchSource = { | ||
highlightAll: true, | ||
version: true, | ||
query: { | ||
language: 'kuery', | ||
query: '', | ||
}, | ||
filter: [ | ||
{ | ||
meta: { | ||
alias: null, | ||
negate: false, | ||
disabled: false, | ||
type: 'phrase', | ||
key: 'airline', | ||
params: { | ||
query: 'AAL', | ||
}, | ||
indexRefName: 'kibanaSavedObjectMeta.searchSourceJSON.filter[0].meta.index', | ||
}, | ||
query: { | ||
match_phrase: { | ||
airline: 'AAL', | ||
}, | ||
}, | ||
$state: { | ||
store: 'appState', | ||
}, | ||
}, | ||
], | ||
indexRefName: 'kibanaSavedObjectMeta.searchSourceJSON.index', | ||
}; | ||
savedSearch.attributes.kibanaSavedObjectMeta.searchSourceJSON = JSON.stringify(searchSource); | ||
|
||
const resp = createSearchItems(kibanaConfig, indexPattern, savedSearch); | ||
expect(resp).toStrictEqual({ | ||
combinedQuery: { | ||
bool: { | ||
must: [{ match_all: {} }], | ||
filter: [{ match_phrase: { airline: 'AAL' } }], | ||
must_not: [], | ||
}, | ||
}, | ||
query: { language: 'kuery', query: '' }, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as you mutate
savedSearch
in each test, it's better to initialize it inbeforeEach
callback to avoid potential issuesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed in 41db653