【发布时间】:2019-05-16 23:46:38
【问题描述】:
我想对 uri 字段执行聚合,但只返回 url 的域部分而不是完整的 url。例如,使用该字段,https://stackoverflow.com/questions/ask?guided=true 我会得到stackoverflow.com
给定一个现有的数据集如下:
"hits" : [
{
"_index" : "people",
"_type" : "_doc",
"_id" : "L9WewGoBZqCeOmbRIMlV",
"_score" : 1.0,
"_source" : {
"firstName" : "George",
"lastName" : "Ouma",
"pageUri" : "http://www.espnfc.com/story/683732/england-football-team-escaped-terrorist-attack-at-1998-world-cup",
"date" : "2019-05-16T12:29:08.1308177Z"
}
},
{
"_index" : "people",
"_type" : "_doc",
"_id" : "MNWewGoBZqCeOmbRIsma",
"_score" : 1.0,
"_source" : {
"firstName" : "George",
"lastName" : "Ouma",
"pageUri" : "http://www.wikipedia.org/wiki/Category:Terrorism_in_Mexico",
"date" : "2019-05-16T12:29:08.1308803Z"
}
},
{
"_index" : "people",
"_type" : "_doc",
"_id" : "2V-ewGoBiHg_1GebJKIr",
"_score" : 1.0,
"_source" : {
"firstName" : "George",
"lastName" : "Ouma",
"pageUri" : "http://www.wikipedia.com/story/683732/england-football-team-escaped-terrorist-attack-at-1998-world-cup",
"date" : "2019-05-16T12:29:08.1308811Z"
}
}
]
我的桶应该是这样的:
"buckets" : [
{
"key" : "www.espnfc.com",
"doc_count" : 1
},
{
"key" : "www.wikipedia.com",
"doc_count" : 2
}
]
我有以下关于我如何进行聚合的代码 sn-p,但是这个聚合基于完整的 url 而不是域名
var searchResponse = client.Search<Person>(s =>
s.Size(0)
.Query(q => q
.MatchAll()
)
.Aggregations(a => a
.Terms("visited_pages", ta => ta
.Field(f => f.PageUri.Suffix("keyword"))
)
)
);
var aggregations = searchResponse.Aggregations.Terms("visited_pages");
任何帮助将不胜感激:)
【问题讨论】:
标签: elasticsearch nest