elasticsearch - 聚合任务如何从 Elasticsearch 中的倒排索引中受益
问题描述
我知道搜索任务可以从 Elasticsearch 中的倒排索引中受益。
但我不明白聚合任务如何从倒排索引中受益。例如,如果我们有以下文档
id, name, gender, age, weight
1, Tom, m, 29, 100
2, James, m, 28, 120
3, Lucy, f, 27, 80
4, Kevin, m, 28, 150
5, Jessica,f, 22, 100
....
如果我想获得年龄 = 28 的平均体重,使用倒排索引弹性搜索的步骤应该是
1. get the doc list of age = 28 which may looks like [id=2, id=4 ...]
2. Read each doc to get the weight
3. Add the weight and divide by the number of records
这似乎效率不高,尤其是对于第 2 步。由于磁盘上的文档位置不连续,因此 Elasticsearch 无法在一次读取中加载数据,因此需要读取很多次。
那么为什么 Elasticsearch 在聚合上能有这么好的表现呢?它是否使用除了倒排索引之外的其他数据结构进行聚合?我对聚合步骤的理解是否错误?
解决方案
这里的关键是要了解倒排索引和其他相关的 Lucene 文件不是在磁盘上访问,而是由 Lucene映射到内存(不是在堆上!)。
因此,无需赘述,这基本上就是 ES 如何在搜索和聚合方面实现出色性能的方式。
推荐阅读
- amazon-web-services - AWS IoT 策略不允许 Cognito WebSocket 客户端订阅主题
- c# - 如何在异步等待 WEB API 中使用 FirstOrDefaultAsync()
- python - 使用 xlutils.copy 保存格式
- r - 爆炸矢量元素并与数据框绑定?
- sql-server - 从我的数据库(SQL 服务器)中的一张表中删除很慢
- sql - 如何根据PostgreSQL中的两列获取指定数据
- excel - Excel VlookUp 左单元格从另一个工作簿进入 VBA
- python - 在 Python 中使用 Arima 预测未来(关键错误)
- java - 无效的输入和循环
- java - JDBC 在服务器上返回空结果集