elasticsearch核心知识--30.分页搜索以及deep paging性能问题深度理解和es中聚合aggregation的分组可能结果不准确的原因
2018-03-26 16:04
1001 查看
如何使用es进行分页搜索的语法 [size,from]
GET /_search?size=10
GET /_search?size=10&from=0
GET /_search?size=10&from=20
GET /test_index/test_type/_search
"hits": {
"total": 9,
"max_score": 1,
我们假设将这9条数据分成3页,每一页是3条数据,来实验一下这个分页搜索的效果
GET /test_index/test_type/_search?from=0&size=3
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 9,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "test_type",
"_id": "8",
"_score": 1,
"_source": {
"test_field": "test client 2"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "6",
"_score": 1,
"_source": {
"test_field": "tes test"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "4",
"_score": 1,
"_source": {
"test_field": "test4"
}
}
]
}
}
第一页:id=8,6,4
GET /test_index/test_type/_search?from=3&size=3
第二页:id=2,自动生成,7
GET /test_index/test_type/_search?from=6&size=3
第三页:id=1,11,3
##########重要::什么是deep paging问题?为什么会产生这个问题,它的底层原理是什么?
deep paging性能问题,以及原理深度。
1.必须1页10条,当我们取第1000页时,在es底层也是需要在每个分片【不限主备shard】取出满足条件的 10010条数据,
如果三个shard ,那么总共在coordination中会load出10010*3=30030条数据,进行排序。然后取出对应的1000页的10条数据。尽量避免深度分页,因为会出现消耗大量的IO 内存 cpu,已经会频繁出现gc。
2.想到了es的aggregation的聚合分组, 如果原始数据中存在10个组,只需要查询统计出三个组。那么会出现数据不准确的问题. 因为会去每个分片中进行分组统计,每个分片中前TopN=Top3会出现 被收集到coordination中 ,再进行聚合排序。再取出前三个组的统计结果。但是可能在每个分片查询时,最终的TopN的数据,排名在3名以上,那么那部分的数据不会被统计进来。所以对aggregation的分组 如果想数据完全正确,要么是单shard的索引。要么时查处全部的分组后,在取前TopN的分组进行统计。
GET /_search?size=10
GET /_search?size=10&from=0
GET /_search?size=10&from=20
GET /test_index/test_type/_search
"hits": {
"total": 9,
"max_score": 1,
我们假设将这9条数据分成3页,每一页是3条数据,来实验一下这个分页搜索的效果
GET /test_index/test_type/_search?from=0&size=3
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 9,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "test_type",
"_id": "8",
"_score": 1,
"_source": {
"test_field": "test client 2"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "6",
"_score": 1,
"_source": {
"test_field": "tes test"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "4",
"_score": 1,
"_source": {
"test_field": "test4"
}
}
]
}
}
第一页:id=8,6,4
GET /test_index/test_type/_search?from=3&size=3
第二页:id=2,自动生成,7
GET /test_index/test_type/_search?from=6&size=3
第三页:id=1,11,3
##########重要::什么是deep paging问题?为什么会产生这个问题,它的底层原理是什么?
deep paging性能问题,以及原理深度。
1.必须1页10条,当我们取第1000页时,在es底层也是需要在每个分片【不限主备shard】取出满足条件的 10010条数据,
如果三个shard ,那么总共在coordination中会load出10010*3=30030条数据,进行排序。然后取出对应的1000页的10条数据。尽量避免深度分页,因为会出现消耗大量的IO 内存 cpu,已经会频繁出现gc。
2.想到了es的aggregation的聚合分组, 如果原始数据中存在10个组,只需要查询统计出三个组。那么会出现数据不准确的问题. 因为会去每个分片中进行分组统计,每个分片中前TopN=Top3会出现 被收集到coordination中 ,再进行聚合排序。再取出前三个组的统计结果。但是可能在每个分片查询时,最终的TopN的数据,排名在3名以上,那么那部分的数据不会被统计进来。所以对aggregation的分组 如果想数据完全正确,要么是单shard的索引。要么时查处全部的分组后,在取前TopN的分组进行统计。
相关文章推荐
- elasticsearch核心知识--46.scroll技术滚动搜索大量数据以及和FromSize分页的本质区别和性能
- elasticsearch核心知识--45.搜索相关参数以及bouncing results问题解决方案
- elasticsearch核心知识--7.aggregation的 嵌套聚合,下钻分析,聚合分析[aggregation和ranges]
- elasticsearch核心知识--42.多搜索条件组合查询,sort以及explain的用法
- elasticsearch聚合操作——本质就是针对搜索后的结果使用桶bucket(允许嵌套)进行group by,统计下分组结果,包括min/max/avg
- elasticsearch搜索结果不准确 搜索不到 的一个问题 ik 特殊符号 空格 拆词
- elasticsearch核心知识--29._multi-index&multi-type搜索模式解析以及搜索原理
- elasticsearch核心知识--17.剖析Elasticsearch并发冲突问题和深度图解剖析悲观锁与乐观锁两种并发控制方案
- elasticsearch核心知识--26.一致性原理以及quorum机制理解
- elasticsearch核心知识--22.mget批量查询api以及性能优化
- sphinx搜索结果不准确,可能的原因之一:docid重复
- sphinx搜索结果不准确,可能的原因之二:字段权重设置的过大,超出32位
- elasticsearch核心知识--35._query string的分词以及默认mapping对_all字段开启的查询问题
- es核心知识篇学习之Elasticsearch 06 ---elasticsearch有六种搜索方式
- sphinx搜索结果不准确,可能的原因之二:字段权重设置的过大,超出32位
- elasticsearch核心知识--44.内核之query phase和fetch phase的理解
- elasticsearch核心知识--39.filter与query对比:相关度,性能
- elasticsearch核心知识---52.倒排索引组成结构以及实现TF-IDF算法
- elasticsearch核心知识---53.图解剖析document写入原理以及Segement的合并
- 准确教小白安装ubuntu14.04以及解决可能遇到的问题