Use new search strategy service for search requests (#58990) (#59292)

* Use new search strategy

* Update jest test

* fix painless error

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Liza Katz 2020-03-04 13:16:06 +00:00 committed by GitHub
parent 66d3a81896
commit 42bf1222b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 21 deletions

View file

@ -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;

View file

@ -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 () => {

View file

@ -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),