Skip to content

Commit f27e45e

Browse files
ddelemenyfmassot
andcommitted
Reduce default terms agg size, add shard_size
Co-Authored-By: François Massot <[email protected]>
1 parent ecca730 commit f27e45e

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

pkg/quickwit/client/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ type FiltersAggregation struct {
260260
type TermsAggregation struct {
261261
Field string `json:"field"`
262262
Size int `json:"size"`
263+
ShardSize int `json:"shard_size"`
263264
Order map[string]interface{} `json:"order"`
264265
MinDocCount *int `json:"min_doc_count,omitempty"`
265266
Missing *string `json:"missing,omitempty"`

pkg/quickwit/data_query.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ func addTermsAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg, metrics []*Metr
229229
} else {
230230
a.Size = stringToIntWithDefaultValue(bucketAgg.Settings.Get("size").MustString(), defaultSize)
231231
}
232+
if shard_size, err := bucketAgg.Settings.Get("shard_size").Int(); err == nil {
233+
a.ShardSize = shard_size
234+
} else {
235+
a.ShardSize = stringToIntWithDefaultValue(bucketAgg.Settings.Get("shard_size").MustString(), defaultSize)
236+
}
232237

233238
if minDocCount, err := bucketAgg.Settings.Get("min_doc_count").Int(); err == nil {
234239
a.MinDocCount = &minDocCount

src/QueryBuilder/elastic.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type OrderByType = '_key' | '_term' | '_count'
1111
function getTermsAgg(
1212
fieldName: string,
1313
size: number,
14+
shard_size: number,
1415
orderBy: OrderByType = "_key",
1516
order: 'asc'|'desc' = 'asc'
1617
): BucketAggregation {
@@ -20,6 +21,7 @@ function getTermsAgg(
2021
field: fieldName,
2122
settings:{
2223
size: size.toString(),
24+
shard_size: shard_size.toString(),
2325
order: order,
2426
orderBy: orderBy,
2527
}
@@ -31,7 +33,8 @@ export function getDataQuery(queryDef: TermsQuery, refId: string): Elasticsearch
3133
{id:"count1", type:'count'}
3234
];
3335

34-
// Default behaviour is to order results by { _key: asc }
36+
// Default behaviour is to order results by { _key: asc } and get 100 terms,
37+
// shard_size is set to 100 to limit terms fetched by shard (by default it's 100 * 10).
3538
// queryDef.order allows selection of asc/desc
3639
// queryDef.orderBy allows selection of doc_count ordering (defaults desc)
3740

@@ -55,7 +58,7 @@ export function getDataQuery(queryDef: TermsQuery, refId: string): Elasticsearch
5558

5659
const bucketAggs: BucketAggregation[] = [];
5760
if (queryDef.field) {
58-
bucketAggs.push(getTermsAgg(queryDef.field, 500, orderBy, order))
61+
bucketAggs.push(getTermsAgg(queryDef.field, 100, 100, orderBy, order))
5962
}
6063

6164
return {

src/dataquery.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export interface Terms extends BucketAggregationWithField {
7171
settings?: {
7272
order?: TermsOrder;
7373
size?: string;
74+
shard_size?: string;
7475
min_doc_count?: string;
7576
orderBy?: string;
7677
missing?: string;

0 commit comments

Comments
 (0)