elasticsearch - ElasticSearch 连接上的术语聚合
问题描述
我想使用 ElasticSearch 7.7 对连接关系执行聚合。
我需要知道每个父母有多少个孩子。我发现解决问题的唯一方法是在术语聚合中使用脚本,但我担心的是性能。
/my_index/_search
{
"size": 0,
"aggs": {
"total": {
"terms": {
"script": {
"lang": "painless",
"source": "params['_source']['my_join']['parent']"
}
}
},
"max_total": {
"max_bucket": {
"buckets_path": "total>_count"
}
}
}
}
有人知道一种更快速的方法来执行这种聚合避免脚本?
如果连接字段不是父/子,我可以将术语聚合替换为:
"terms": { "field": "my_field" }
为了提供更多上下文,我添加了一些有关映射的信息:
我正在使用弹性 7.7。
我还附上了一些示例文档的映射:
{
"mappings": {
"properties": {
"my_join": {
"relations": {
"other": "doc"
},
"type": "join"
},
"reader": {
"type": "keyword"
},
"name": {
"type": "text"
},
"content": {
"type": "text"
}
}
}
}
PUT example/_doc/1
{
"reader": [
"A",
"B"
],
"my_join": {
"name": "other"
}
}
PUT example/_doc/2
{
"reader": [
"A",
"B"
],
"my_join": {
"name": "other"
}
}
PUT example/_doc/3
{
"content": "abc",
"my_join": {
"name": "doc",
"parent": 1
}
}
PUT example/_doc/4
{
"content": "def",
"my_join": {
"name": "doc"
"parent": 2
}
}
PUT example/_doc/5
{
"content": "def",
"acl_join": {
"name": "doc"
"parent": 1
}
}
解决方案
推荐阅读
- iframe - 我希望主页在没有模式 iframe 加载的情况下打开
- c# - 使用带有单选按钮的 Switch Case 并将结果附加到列表框
- c - 从C中的文本文件中读取行
- ios - 在 UIAlertController 操作中使用云函数时是否存在竞争条件?
- sharepoint - 使用 SharePoint Online,如何删除属于“链接”而不是“帖子”的新闻项目?
- oracle - 对oracle表中的多值列进行排序
- javascript - 在 redux 中将一个更大的 reducer 的一部分委托给它自己的 reducer
- mutt - 为什么 mutt 电子邮件可能会被 windows 收件人接受/拒绝作为正在发送的 html 文件正文中的字母字符串内容的函数?
- swift - 在 SwiftUI 中以编程方式移动 NavigationView 的最佳实践是什么
- java - 为每个 Observable 调用的 RX Java 2 onComplete 方法