elasticsearch - 数组上的术语聚合

标签 elasticsearch nest elasticsearch-aggregation

索引字段有问题,该索引字段以以下方式存储字符串列表:

[“abc_def_fgh”,“abc_def_fgh”,“123_345_456”]

我正在尝试使用TermsAggregation来获取

“abc_def_fgh”(2)
“123_345_456”(1)

但是无法使其正常工作,因为它会得出每个术语的计数(abc(2),def(2)等)

任何的想法?

非常感谢

最佳答案

尝试类似的东西

var result = await client.SearchAsync<Document>(s => s
    .Size(0)
    .Aggregations(a => a
        .Terms("tags", t => t.Field(f => f.Tags.Suffix("keyword")))));

foreach (var bucket in result.Aggregations.Terms("tags").Buckets)
{
    System.Console.WriteLine($"Tag {bucket.Key}, doc count: {bucket.DocCount}");
}

public class Document
{
    public string Id { get; set; }
    public string[] Tags { get; set; } = { };
}

我索引中的这三个文件
new Document {Id = "1", Tags = new[]{"a","b"}
new Document {Id = "2", Tags = new[]{"a"}
new Document {Id = "3", Tags = new[]{"c"}

它会输出
Tag a, doc count: 2
Tag b, doc count: 1
Tag c, doc count: 1

希望能有所帮助。

关于elasticsearch - 数组上的术语聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60130534/

相关文章:

c# - 值列表中的值存在于弹性字段列表嵌套C#中

elasticsearch - ElasticSearch中的实用分析和搜索策略用例

elasticsearch - 具有过滤器的 Elasticsearch 聚合无法过滤聚合

elasticsearch - 只需要汇总查询结果

elasticsearch - 如何在不使用小写的情况下使用Elasticsearch标准分析器

elasticsearch - 在Elasticsearch上自动创建快照存储库-Kubernetes

c# - 使用NEST使用ElasticSearch 2.x搜索多种类型时,如何得到混合结果?

elasticsearch - 使Elasticsearch Aggregation无法正常工作

elasticsearch - 可以将作为 Web 服务公开的日志数据输入到 Elasticsearch 吗?

elasticsearch - 使用grok过滤Logstash中的Apache错误日志