Skip to content

Commit

Permalink
Use new search strategy service for search requests (#58990) (#59292)
Browse files Browse the repository at this point in the history
* Use new search strategy

* Update jest test

* fix painless error

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
Liza Katz and elasticmachine authored Mar 4, 2020
1 parent 66d3a81 commit 42bf122
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import { get } from 'lodash';
export function getPainlessError(error: Error) {
const rootCause: Array<{ lang: string; script: string }> | undefined = get(
error,
'resp.error.root_cause'
'body.attributes.error.root_cause'
);
const message: string = get(error, 'message');
const message: string = get(error, 'body.message');

if (!rootCause) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ describe('defaultSearchStrategy', function() {
test('should call new search service', () => {
const config = getConfigStub();
search({ ...searchArgs, config });
expect(searchMock).toHaveBeenCalled();
expect(newSearchMock).toHaveBeenCalledTimes(0);
expect(newSearchMock).toHaveBeenCalledTimes(1);
});

test('should properly abort with new search service', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,17 @@ function search({
}: SearchStrategySearchParams) {
const abortController = new AbortController();
const searchParams = getSearchParams(config, esShardTimeout);
const es = searchService.__LEGACY.esClient;
const promises = searchRequests.map(({ index, body }) => {
const searching = es.search({ index: index.title || index, body, ...searchParams });
abortController.signal.addEventListener('abort', searching.abort);
return searching.catch(({ response }: any) => JSON.parse(response));
/*
* Once #44302 is resolved, replace the old implementation with this one -
* const params = {
* index: index.title || index,
* body,
* ...searchParams,
* };
* const { signal } = abortController;
* return searchService
* .search({ params }, { signal })
* .toPromise()
* .then(({ rawResponse }) => rawResponse);
*/
const params = {
index: index.title || index,
body,
...searchParams,
};
const { signal } = abortController;
return searchService
.search({ params }, { signal })
.toPromise()
.then(({ rawResponse }) => rawResponse);
});
return {
searching: Promise.all(promises),
Expand Down

0 comments on commit 42bf122

Please sign in to comment.