-
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
[context view] Use courier when querying the context #11127
Merged
weltenwort
merged 6 commits into
elastic:master
from
weltenwort:refactoring/context-courier-query
Apr 18, 2017
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
42e2b71
Perform the context queries via a SearchSource
weltenwort 5635616
Adapt tests
weltenwort eaa2d0f
Remove code for deprecated query code path
weltenwort 7d38d05
Remove unused utility function
weltenwort bf8ddb5
Use timefilter.getActiveBounds()
weltenwort a03bf50
Fix usages of default exports
weltenwort 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
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
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 |
---|---|---|
@@ -1,31 +1,41 @@ | ||
import _ from 'lodash'; | ||
|
||
import { addComputedFields } from './utils/fields'; | ||
import { createAnchorQueryBody } from './utils/queries'; | ||
|
||
|
||
async function fetchAnchor(es, indexPattern, uid, sort) { | ||
const indices = await indexPattern.toIndexList(); | ||
const queryBody = addComputedFields(indexPattern, createAnchorQueryBody(uid, sort)); | ||
const response = await es.search({ | ||
index: indices, | ||
body: queryBody, | ||
}); | ||
|
||
if (_.get(response, ['hits', 'total'], 0) < 1) { | ||
throw new Error('Failed to load anchor document.'); | ||
} | ||
|
||
return Object.assign( | ||
{}, | ||
response.hits.hits[0], | ||
{ | ||
$$_isAnchor: true, | ||
}, | ||
); | ||
import { SearchSourceProvider } from 'ui/courier/data_source/search_source'; | ||
|
||
|
||
function fetchAnchorProvider(Private) { | ||
const SearchSource = Private(SearchSourceProvider); | ||
|
||
return async function fetchAnchor(indexPattern, uid, sort) { | ||
const searchSource = new SearchSource() | ||
.inherits(false) | ||
.set('index', indexPattern) | ||
.set('version', true) | ||
.set('size', 1) | ||
.set('query', { | ||
terms: { | ||
_uid: [uid], | ||
}, | ||
}) | ||
.set('sort', [sort, { _uid: 'asc' }]); | ||
|
||
const response = await searchSource.fetch(); | ||
|
||
if (_.get(response, ['hits', 'total'], 0) < 1) { | ||
throw new Error('Failed to load anchor document.'); | ||
} | ||
|
||
return Object.assign( | ||
{}, | ||
_.get(response, ['hits', 'hits', 0]), | ||
{ | ||
$$_isAnchor: true, | ||
}, | ||
); | ||
}; | ||
} | ||
|
||
|
||
export { | ||
fetchAnchor, | ||
fetchAnchorProvider, | ||
}; |
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 |
---|---|---|
@@ -1,46 +1,64 @@ | ||
import _ from 'lodash'; | ||
|
||
import { addComputedFields } from './utils/fields'; | ||
import { createSuccessorsQueryBody } from './utils/queries.js'; | ||
import { reverseQuerySort } from './utils/sorting'; | ||
import { SearchSourceProvider } from 'ui/courier/data_source/search_source'; | ||
|
||
import { reverseSortDirective } from './utils/sorting'; | ||
|
||
async function fetchSuccessors(es, indexPattern, anchorDocument, sort, size) { | ||
const successorsQueryBody = prepareQueryBody(indexPattern, anchorDocument, sort, size); | ||
const results = await performQuery(es, indexPattern, successorsQueryBody); | ||
return results; | ||
} | ||
|
||
async function fetchPredecessors(es, indexPattern, anchorDocument, sort, size) { | ||
const successorsQueryBody = prepareQueryBody(indexPattern, anchorDocument, sort, size); | ||
const predecessorsQueryBody = reverseQuerySort(successorsQueryBody); | ||
const reversedResults = await performQuery(es, indexPattern, predecessorsQueryBody); | ||
const results = reversedResults.slice().reverse(); | ||
return results; | ||
} | ||
function fetchContextProvider(Private) { | ||
const SearchSource = Private(SearchSourceProvider); | ||
|
||
return { | ||
fetchPredecessors, | ||
fetchSuccessors, | ||
}; | ||
|
||
function prepareQueryBody(indexPattern, anchorDocument, sort, size) { | ||
const successorsQueryBody = addComputedFields( | ||
indexPattern, | ||
createSuccessorsQueryBody(anchorDocument.sort, sort, size) | ||
); | ||
return successorsQueryBody; | ||
} | ||
async function fetchSuccessors(indexPattern, anchorDocument, contextSort, size) { | ||
const successorsSort = [contextSort, { _uid: 'asc' }]; | ||
const successorsSearchSource = createSearchSource( | ||
indexPattern, | ||
anchorDocument, | ||
successorsSort, | ||
size, | ||
); | ||
const results = await performQuery(successorsSearchSource); | ||
return results; | ||
} | ||
|
||
async function fetchPredecessors(indexPattern, anchorDocument, contextSort, size) { | ||
const predecessorsSort = [reverseSortDirective(contextSort), { _uid: 'desc' }]; | ||
const predecessorsSearchSource = createSearchSource( | ||
indexPattern, | ||
anchorDocument, | ||
predecessorsSort, | ||
size, | ||
); | ||
const reversedResults = await performQuery(predecessorsSearchSource); | ||
const results = reversedResults.slice().reverse(); | ||
return results; | ||
} | ||
|
||
async function performQuery(es, indexPattern, queryBody) { | ||
const indices = await indexPattern.toIndexList(); | ||
function createSearchSource(indexPattern, anchorDocument, sort, size) { | ||
return new SearchSource() | ||
.inherits(false) | ||
.set('index', indexPattern) | ||
.set('version', true) | ||
.set('size', size) | ||
.set('query', { | ||
match_all: {}, | ||
}) | ||
.set('searchAfter', anchorDocument.sort) | ||
.set('sort', sort); | ||
} | ||
|
||
const response = await es.search({ | ||
index: indices, | ||
body: queryBody, | ||
}); | ||
async function performQuery(searchSource) { | ||
const response = await searchSource.fetch(); | ||
|
||
return _.get(response, ['hits', 'hits'], []); | ||
return _.get(response, ['hits', 'hits'], []); | ||
} | ||
} | ||
|
||
|
||
export { | ||
fetchPredecessors, | ||
fetchSuccessors, | ||
fetchContextProvider, | ||
}; |
49 changes: 0 additions & 49 deletions
49
src/core_plugins/kibana/public/context/api/utils/__tests__/fields.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
I'm trying to figure out what exactly this line accomplishes... Does the
SearchSource
inherit something else by default?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.
Yes, it takes a while to trace the effect. Ultimately it disables the default inheritance from the
rootSearchSource
:kibana/src/ui/public/courier/data_source/search_source.js
Lines 151 to 156 in 9043476
This is how the the timefilter values get mixed into the request, which I needed to disable for the context query.