in lib/protocol/encoder.js [790:865]
_constructAggregationParam(aggType, agg) {
switch (aggType) {
case TableStore.AggregationType.AGG_AVG: {
const properties = {
fieldName: agg.fieldName,
};
if (agg.missing) {
properties.missing = TableStore.PlainBufferBuilder.serializeSearchValue(agg.missing, "agg.missing");
}
return tsSearchProtos.AvgAggregation.create(properties);
}
case TableStore.AggregationType.AGG_MAX: {
const properties = {
fieldName: agg.fieldName,
};
if (agg.missing) {
properties.missing = TableStore.PlainBufferBuilder.serializeSearchValue(agg.missing, "agg.missing");
}
return tsSearchProtos.MaxAggregation.create(properties);
}
case TableStore.AggregationType.AGG_MIN: {
const properties = {
fieldName: agg.fieldName,
};
if (agg.missing) {
properties.missing = TableStore.PlainBufferBuilder.serializeSearchValue(agg.missing, "agg.missing");
}
return tsSearchProtos.MinAggregation.create(properties);
}
case TableStore.AggregationType.AGG_SUM: {
const properties = {
fieldName: agg.fieldName,
};
if (agg.missing) {
properties.missing = TableStore.PlainBufferBuilder.serializeSearchValue(agg.missing, "agg.missing");
}
return tsSearchProtos.SumAggregation.create(properties);
}
case TableStore.AggregationType.AGG_COUNT: {
const properties = {
fieldName: agg.fieldName,
};
return tsSearchProtos.CountAggregation.create(properties);
}
case TableStore.AggregationType.AGG_DISTINCT_COUNT: {
const properties = {
fieldName: agg.fieldName,
};
if (agg.missing) {
properties.missing = TableStore.PlainBufferBuilder.serializeSearchValue(agg.missing, "agg.missing");
}
return tsSearchProtos.DistinctCountAggregation.create(properties);
}
case TableStore.AggregationType.AGG_TOP_ROWS: {
const properties = {
limit: agg.limit,
};
if (agg.sort) {
properties.sort = TableStore.encoder._makeSort(agg.sort);
}
return tsSearchProtos.TopRowsAggregation.create(properties);
}
case TableStore.AggregationType.AGG_PERCENTILES: {
const properties = {
fieldName: agg.fieldName,
percentiles: agg.percentiles,
};
if (agg.missing) {
properties.missing = TableStore.PlainBufferBuilder.serializeSearchValue(agg.missing, "agg.missing");
}
return tsSearchProtos.PercentilesAggregation.create(properties);
}
default:
throw new Error("not exist AggregationType: " + aggType);
}
},