diff --git a/src/QueryBuilder/elastic.ts b/src/QueryBuilder/elastic.ts index 96f9340..a551c3a 100644 --- a/src/QueryBuilder/elastic.ts +++ b/src/QueryBuilder/elastic.ts @@ -11,6 +11,7 @@ type OrderByType = '_key' | '_term' | '_count' function getTermsAgg( fieldName: string, size: number, + segment_size: number, orderBy: OrderByType = "_key", order: 'asc'|'desc' = 'asc' ): BucketAggregation { @@ -20,6 +21,7 @@ function getTermsAgg( field: fieldName, settings:{ size: size.toString(), + segment_size: segment_size.toString(), order: order, orderBy: orderBy, } @@ -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, + // segment_size is set to 100 to limit terms fetched by segment (by default it's 100 * 10). // queryDef.order allows selection of asc/desc // queryDef.orderBy allows selection of doc_count ordering (defaults desc) @@ -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 { diff --git a/src/dataquery.gen.ts b/src/dataquery.gen.ts index efe68c0..6c0fdee 100644 --- a/src/dataquery.gen.ts +++ b/src/dataquery.gen.ts @@ -71,6 +71,7 @@ export interface Terms extends BucketAggregationWithField { settings?: { order?: TermsOrder; size?: string; + segment_size?: string; min_doc_count?: string; orderBy?: string; missing?: string; diff --git a/src/datasource/utils.ts b/src/datasource/utils.ts index 82663b7..ce2602a 100644 --- a/src/datasource/utils.ts +++ b/src/datasource/utils.ts @@ -27,14 +27,14 @@ export function useDatasourceFields(datasource: BaseQuickwitDataSource) { const getSuggestions = useCallback(async (word: string): Promise => { let suggestions: Suggestion = { from: 0, options: [] }; - const wordIsField = word.match(/([^:\s]+):"?([^"\s]*)"?/); + const wordIsField = word.match(/([^:\s]+):'?([^'\s]*)'?/); if (wordIsField?.length) { const [_match, fieldName, _fieldValue] = wordIsField; const candidateValues = await datasource.getTagValues({ key: fieldName }); suggestions.from = fieldName.length + 1; // Replace only the value part suggestions.options = candidateValues.map(v => ({ type: 'text', - label: typeof v.text === 'number' ? `${v.text}` : `"${v.text}"` + label: typeof v.text === 'number' ? `${v.text}` : `'${v.text}'` })); } else { const candidateFields = fields; diff --git a/src/utils/lucene.ts b/src/utils/lucene.ts index 99e0275..b6fbaae 100644 --- a/src/utils/lucene.ts +++ b/src/utils/lucene.ts @@ -196,7 +196,7 @@ export class LuceneQuery { key = escapeFilter(key); value = escapeFilterValue(value); - const filter = `${modifier}${key}:"${value}"`; + const filter = `${modifier}${key}:'${value}'`; return LuceneQuery.parse(concatenate(this.toString(), filter)); }