AggregationBucket
One bucket of a bucket-aggregation result, as returned by SearchAsync() when the request used SearchAggregation. Related output types (AggregationHit, AggregationHitField, AggregationBucketKey) are documented in the sections below.
public sealed class AggregationBucket
{
public IReadOnlyList<AggregationBucketKey> Key { get; }
public long Count { get; }
public IReadOnlyDictionary<string, object?> Metrics { get; }
public IReadOnlyList<AggregationHit> Hits { get; }
public IReadOnlyList<AggregationBucket> SubGroups { get; }
}
PARAMETERS:
Key(IReadOnlyList) - The bucket key values, aligned with the group-by fields.
Count(long) -The number of documents in the bucket.
Metrics(IReadOnlyDictionary) - The metric values keyed by metric alias. Values are a
long,double,stringorbool.Hits(IReadOnlyList) - The top hits of the bucket.
SubGroups(IReadOnlyList) - The nested sub-buckets.
AggregationBucketKey
The key value of an aggregation bucket, defined by the group-by fields of one query.
public sealed class AggregationBucketKey
{
public long FieldId { get; }
public string FieldName { get; }
public object? Value { get; }
}
PARAMETERS:
FieldId(long) -The ID of the field.
FieldName(string) -The name of the field.
Value(object?) -The group-by field value of the bucket (a
long,stringorbool).
AggregationHit
A top-hit document of an aggregation bucket.
public sealed class AggregationHit
{
public object? Id { get; }
public float Score { get; }
public IReadOnlyList<AggregationHitField> Fields { get; }
}
PARAMETERS:
Id(object?) -The primary key of the document.
Score(float) -The relevance score of the document.
Fields(IReadOnlyList) - The field values of the document.
AggregationHitField
A single field value of an aggregation top-hit document.
public sealed class AggregationHitField
{
public long FieldId { get; }
public string FieldName { get; }
public object? Value { get; }
}
PARAMETERS:
FieldId(long) -The ID of the field.
FieldName(string) -The name of the field.
Value(object?) -The field value (a
long,bool,float,double,stringorbyte[]).
Example
using Milvus.Client.V2;
using Milvus.Client.V2.Requests.Dql;
using Milvus.Client.V2.Responses.Dql;
using Milvus.Client.V2.Types;
using var client = new MilvusClientV2(new ConnectConfig
{
Uri = "localhost:19530",
Username = "root",
Password = "Milvus"
});
SearchResp results = await client.SearchAsync(new SearchReq
{
CollectionName = "my_collection",
VectorFieldName = "embedding",
Vectors = [new[] { 0.1f, 0.2f, 0.3f, 0.4f }],
Limit = 5,
SearchAggregation = new SearchAggregation
{
Fields = { "category" },
Size = 10
}
});
foreach (IReadOnlyList<AggregationBucket> buckets in results.AggregationBuckets ?? [])
{
foreach (AggregationBucket bucket in buckets)
{
Console.WriteLine($"{bucket.Key[0].Value}: {bucket.Count}");
}
}