-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use term aggregations /w execution_hint:map for events - 100x speedup…
… on the MVP cluster (#66) * Remove aggregations from events query - 5x speedup on MVP * Add compatibility wrappers * Speed up aggs with execution_hint: 'map' and apply compat wrappers
- Loading branch information
1 parent
0e5caec
commit 58980f4
Showing
6 changed files
with
96 additions
and
29 deletions.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
// Code that works around incompatibilities between different | ||
// versions of Kibana / ES. | ||
// Currently, we work with 8.1 and 8.3 and thus this code only needs | ||
// to address the incompatibilities between those two versions. | ||
|
||
import type { TransportResult } from '@elastic/transport/lib/types'; | ||
import type { | ||
SearchResponse, | ||
SearchHitsMetadata, | ||
SearchHit, | ||
MgetResponse, | ||
MgetResponseItem, | ||
AggregationsAggregate, | ||
} from '@elastic/elasticsearch/lib/api/types'; | ||
import type { ElasticsearchClient } from 'kibana/server'; | ||
import type { DataRequestHandlerContext } from '../../../data/server'; | ||
|
||
// Search results in 8.1 have 'body' but not in 8.3. | ||
export function getHits( | ||
res: TransportResult<SearchResponse<unknown, Record<string, AggregationsAggregate>>, unknown> | ||
): SearchHitsMetadata<unknown> { | ||
return 'body' in res ? res.body.hits : res.hits; | ||
} | ||
|
||
export function getAggs( | ||
res: TransportResult<SearchResponse<unknown, Record<string, AggregationsAggregate>>, unknown> | ||
): Record<string, AggregationsAggregate> | undefined { | ||
return 'body' in res ? res.body.aggregations : res.aggregations; | ||
} | ||
|
||
export function getHitsItems( | ||
res: TransportResult<SearchResponse<unknown, Record<string, AggregationsAggregate>>, unknown> | ||
): Array<SearchHit<unknown>> { | ||
return getHits(res)?.hits ?? []; | ||
} | ||
|
||
// Mget results in 8.1 have 'body' but not in 8.3. | ||
export function getDocs( | ||
res: TransportResult<MgetResponse<any>, unknown> | ||
): Array<MgetResponseItem<any>> { | ||
return ('body' in res ? res.body.docs : res.docs) ?? []; | ||
} | ||
|
||
// In 8.3, context.core is a Promise. | ||
export async function getClient(context: DataRequestHandlerContext): Promise<ElasticsearchClient> { | ||
return typeof context.core.then === 'function' | ||
? (await context.core).elasticsearch.client.asCurrentUser | ||
: context.core.elasticsearch.client.asCurrentUser; | ||
} |
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
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