Skip to content
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

Reduce default terms agg size, add shard_size #109

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/quickwit/client/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ type FiltersAggregation struct {
type TermsAggregation struct {
Field string `json:"field"`
Size int `json:"size"`
ShardSize int `json:"shard_size"`
Order map[string]interface{} `json:"order"`
MinDocCount *int `json:"min_doc_count,omitempty"`
Missing *string `json:"missing,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/quickwit/data_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ func addTermsAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg, metrics []*Metr
} else {
a.Size = stringToIntWithDefaultValue(bucketAgg.Settings.Get("size").MustString(), defaultSize)
}
if shard_size, err := bucketAgg.Settings.Get("shard_size").Int(); err == nil {
a.ShardSize = shard_size
} else {
a.ShardSize = stringToIntWithDefaultValue(bucketAgg.Settings.Get("shard_size").MustString(), defaultSize)
}

if minDocCount, err := bucketAgg.Settings.Get("min_doc_count").Int(); err == nil {
a.MinDocCount = &minDocCount
Expand Down
7 changes: 5 additions & 2 deletions src/QueryBuilder/elastic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type OrderByType = '_key' | '_term' | '_count'
function getTermsAgg(
fieldName: string,
size: number,
shard_size: number,
orderBy: OrderByType = "_key",
order: 'asc'|'desc' = 'asc'
): BucketAggregation {
Expand All @@ -20,6 +21,7 @@ function getTermsAgg(
field: fieldName,
settings:{
size: size.toString(),
shard_size: shard_size.toString(),
order: order,
orderBy: orderBy,
}
Expand All @@ -31,7 +33,8 @@ export function getDataQuery(queryDef: TermsQuery, refId: string): Elasticsearch
{id:"count1", type:'count'}
];

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

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

const bucketAggs: BucketAggregation[] = [];
if (queryDef.field) {
bucketAggs.push(getTermsAgg(queryDef.field, 500, orderBy, order))
bucketAggs.push(getTermsAgg(queryDef.field, 100, 100, orderBy, order))
}

return {
Expand Down
1 change: 1 addition & 0 deletions src/dataquery.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface Terms extends BucketAggregationWithField {
settings?: {
order?: TermsOrder;
size?: string;
shard_size?: string;
min_doc_count?: string;
orderBy?: string;
missing?: string;
Expand Down
Loading