c# - Elasticsearch 术语聚合返回空存储桶
问题描述
我正在使用 Elasticsearch 术语聚合从字段中获取唯一值。以下是我使用的代码:
var res = client.Search<KibanaFaxLog>(s => s
.Size(0)
.Query(q => q.MatchAll())
.Aggregations(a => a
.Terms("servers", t => t
.Field(f => f.ServerURL.Suffix("keyword")))
)
);
result = JsonConvert.SerializeObject(res.Aggregations.Terms("servers").Buckets);
我收到空桶的响应:[{},{}]
以下是我在 Kibana 开发工具中使用的 DSL 查询,它准确地返回了结果。
GET efax/_search
{
"size": 0,
"aggregations" : {
"urls" : {
"terms" : { "field" : "ServerURL.keyword"}
}
}}
这似乎是什么问题?
编辑:以下是文档
{
"_index" : "efax",
"_type" : "_doc",
"_id" : "-VRqgHABF0HYEOSDNhHT",
"_score" : 1.0,
"_source" : {
"PracticeId" : 2,
"PracticeName" : "Neighborhood Physcians Practice",
"ServerName" : "baseline01",
"DataBaseName" : "202685DEV",
"ServerURL" : "localhost",
"Status" : -1003,
"TransactionId" : "",
"Action" : "Send Fax",
"SenderFaxNumber" : "555",
"RecipientFaxNumber" : "444",
"FaxUser" : "demo.number",
"FaxSystem" : "efaxer",
"QueryString" : "ID=483",
"ActivityTime" : "2020-02-21T08:54:51.648363-05:00",
"ActivityTimeUTC" : "2020-02-21T13:54:51.648363Z",
"FailureMessage" : "Authentication error"
}
编辑:这是我正在聚合的特定字段的映射
{...
"ServerURL": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},...
}
编辑:我启用了调试信息并得到了以下响应。
"Successful (200) low level call on POST: /efax/_search?pretty=true&error_trace=true&typed_keys=true # Audit trail of this API call: - [1] HealthyResponse: Node: http://xxx:9200/ Took: 00:00:01.0937463 # Request: {"aggs":{"servers":{"terms":{"field":"ServerURL.keyword"}}},"query":{"match_all":{}},"size":0} # Response: { "took" : 0, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 23, "max_score" : 0.0, "hits" : [ ] }, "aggregations" : { "sterms#servers" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "ccc.com", "doc_count" : 8 }, { "key" : "http://localhost/", "doc_count" : 5 }, { "key" : "http://www.ccc.com/202685", "doc_count" : 5 }, { "key" : "localhost", "doc_count" : 5 } ] } } } "
在调试信息中似乎请求和响应都很好,但是我上面显示的聚合对象仍然是空的
解决方案
推荐阅读
- mysql - 是否可以使用 mysql_user ansible 模块删除 mysql root 用户进行远程登录?
- java - 当参数是给定类型的子类时如何调用重载方法?
- amazon-web-services - 字体未从 aws s3 加载(400 错误请求)
- php - PHP / htaccess中带有正斜杠的GET参数
- react-native - Metro bundler 不会随着 expo start 自动启动
- r - 如果我使用交互图,如何在 GGplot2 中添加误差线
- docker - 如何在 Shibboleth xml 文件中使用/访问 docker 环境变量?
- java - 数据未显示在 jTable 中,其中没有数据出现
- sql - 重新排序表的字段
- kubernetes - 如何使用 kubectl 或 Web UI 登录 prometheus pod