【elasticsearch】关于elasticsearch的max_result_window限制问题的解决方式思考

事情起因:我们使用es作为日志搜索引擎,客户收集到的业务日志非常之大,每次查询后,返回页数较多,由于我们web界面限制每页返回150条,当客户翻到66页之后就会报错。

文章目录

前言

二、实验

1.默认生成20条数据

2.默认查询

3.Search after查询

4.Search after二次查询

总结


前言

报错信息如下:

  • Elasticsearch limits the search result to 10000 messages. With a page size of 150 messages, you can use the first 66 pages. Unable to perform search query: Elasticsearch exception [type=illegal_argument_exception, reason=Result window is too large, from + size must be less than or equal to: [10000] but was [34050]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.].

一、Search after介绍

        使用Search after作为查询,默认情况下我们使用Scroll search作为查询,可以指定From + size 大小的数据批量返回,这是为了防止因为请求过多的结果而导致内存和CPU资源过度消耗。

        查询结果的分页可以通过使用from and size 来完成,但是当达到深度分页时,成本变得令人望而却步。 默认为 10000 是一种保护措施,搜索请求占用的堆内存和时间成正比。 建议使用 scroll API 来实现高效的深度滚动,但滚动上下文成本高昂,而且成本不高,建议将其用于实时用户请求。 Search after通过提供实时游标来规避此问题。 这个想法是使用上一页的结果来帮助检索下一页。

二、实验

1.默认生成20条数据

for i in `seq 1 20`
do echo 192.168.113.195 -d -P 54000 "zhongguoren $i"sleep 1
done

2.默认查询

GET index_1/_search
{"query": {"match": {"message": "zhongguoren"}},"sort": [{"timestamp": "asc"}]
}

默认返回20条数据,通过默认查询知识确认,每条信息的流入时间和条数,目前按照1-20进行排序,没有重复的时间戳。

3.Search after查询

index_1/_search
{"size": 10,"query": {"match": {"message": "zhongguoren"}},"sort": [{"timestamp": "asc"},{"_id": "asc"}]
}

先查询前10条,这个和之前默认查询有个区别,就是排序时通过timestamp和_id进行同时排序,在查询结果中得到一个sort字段,值为

"sort": [ - 
          1680770417895,
          "a894bf71-d456-11ed-aa52-000c29f6b211"
        ]

查询后结果值为:

{ - "took": 223,"timed_out": false,"_shards": { - "total": 4,"successful": 4,"skipped": 0,"failed": 0},"hits": { - "total": { - "value": 20,"relation": "eq"},"max_score": null,"hits": [ - { - "_index": "12_149","_type": "_doc","_id": "2df06a80-d456-11ed-aa52-000c29f6b211","_score": null,"_source": { - "elap_accounted_message_size": 140,"elap_source_input": "636c90d3246ca975ec999b24","streams": [ - "6969696969697379736c6f67","6969696969727379736c6f67"],"elap_remote_port": 35834,"elap_source_node": "5bb5d963-7fdd-4e2d-bfdf-a5069bb07097","source": "192.168.113.195","elap_message_id": "01GXAVC899ZZXDJXF453F0RVXJ","message": "<5>Apr 6 16:36:52 root: zhongguoren 1","elap_remote_ip": "192.168.113.195","timestamp": "2023-04-06 08:36:52.135"},"sort": [ - 1680770212135,"2df06a80-d456-11ed-aa52-000c29f6b211"]},{ - "_index": "12_149","_type": "_doc","_id": "5244ccf0-d456-11ed-aa52-000c29f6b211","_score": null,"_source": { - "elap_accounted_message_size": 140,"elap_source_input": "636c90d3246ca975ec999b24","streams": [ - "6969696969697379736c6f67","6969696969727379736c6f67"],"elap_remote_port": 52885,"elap_source_node": "5bb5d963-7fdd-4e2d-bfdf-a5069bb07097","source": "192.168.113.195","elap_message_id": "01GXAVE3XCWZK71D74YVF58PZ2","message": "<5>Apr 6 16:37:53 root: zhongguoren 2","elap_remote_ip": "192.168.113.195","timestamp": "2023-04-06 08:37:53.086"},"sort": [ - 1680770273086,"5244ccf0-d456-11ed-aa52-000c29f6b211"]},{ - "_index": "12_149","_type": "_doc","_id": "5e46d610-d456-11ed-aa52-000c29f6b211","_score": null,"_source": { - "elap_accounted_message_size": 140,"elap_source_input": "636c90d3246ca975ec999b24","streams": [ - "6969696969697379736c6f67","6969696969727379736c6f67"],"elap_remote_port": 57417,"elap_source_node": "5bb5d963-7fdd-4e2d-bfdf-a5069bb07097","source": "192.168.113.195","elap_message_id": "01GXAVEQFJP3CN17A2NG41YYHY","message": "<5>Apr 6 16:38:13 root: zhongguoren 3","elap_remote_ip": "192.168.113.195","timestamp": "2023-04-06 08:38:13.232"},"sort": [ - 1680770293232,"5e46d610-d456-11ed-aa52-000c29f6b211"]},{ - "_index": "12_149","_type": "_doc","_id": "644eb870-d456-11ed-aa52-000c29f6b211","_score": null,"_source": { - "elap_accounted_message_size": 140,"elap_source_input": "636c90d3246ca975ec999b24","streams": [ - "6969696969697379736c6f67","6969696969727379736c6f67"],"elap_remote_port": 52483,"elap_source_node": "5bb5d963-7fdd-4e2d-bfdf-a5069bb07097","source": "192.168.113.195","elap_message_id": "01GXAVF1BQNJZ48GW39G48DQNQ","message": "<5>Apr 6 16:38:23 root: zhongguoren 4","elap_remote_ip": "192.168.113.195","timestamp": "2023-04-06 08:38:23.350"},"sort": [ - 1680770303350,"644eb870-d456-11ed-aa52-000c29f6b211"]},{ - "_index": "12_149","_type": "_doc","_id": "a562e070-d456-11ed-aa52-000c29f6b211","_score": null,"_source": { - "elap_accounted_message_size": 140,"elap_source_input": "636c90d3246ca975ec999b24","streams": [ - "6969696969697379736c6f67","6969696969727379736c6f67"],"elap_remote_port": 45404,"elap_source_node": "5bb5d963-7fdd-4e2d-bfdf-a5069bb07097","source": "192.168.113.195","elap_message_id": "01GXAVJC1YT9SPVWG81CJGBMXG","message": "<5>Apr 6 16:40:12 root: zhongguoren 5","elap_remote_ip": "192.168.113.195","timestamp": "2023-04-06 08:40:12.534"},"sort": [ - 1680770412534,"a562e070-d456-11ed-aa52-000c29f6b211"]},{ - "_index": "12_149","_type": "_doc","_id": "a609f5e0-d456-11ed-aa52-000c29f6b211","_score": null,"_source": { - "elap_accounted_message_size": 140,"elap_source_input": "636c90d3246ca975ec999b24","streams": [ - "6969696969697379736c6f67","6969696969727379736c6f67"],"elap_remote_port": 33127,"elap_source_node": "5bb5d963-7fdd-4e2d-bfdf-a5069bb07097","source": "192.168.113.195","elap_message_id": "01GXAVJD1Y45HAS4N7ZN2YXWS0","message": "<5>Apr 6 16:40:13 root: zhongguoren 6","elap_remote_ip": "192.168.113.195","timestamp": "2023-04-06 08:40:13.629"},"sort": [ - 1680770413629,"a609f5e0-d456-11ed-aa52-000c29f6b211"]},{ - "_index": "12_149","_type": "_doc","_id": "a6a328a0-d456-11ed-aa52-000c29f6b211","_score": null,"_source": { - "elap_accounted_message_size": 140,"elap_source_input": "636c90d3246ca975ec999b24","streams": [ - "6969696969697379736c6f67","6969696969727379736c6f67"],"elap_remote_port": 41301,"elap_source_node": "5bb5d963-7fdd-4e2d-bfdf-a5069bb07097","source": "192.168.113.195","elap_message_id": "01GXAVJE1A0ER5S5BZ8DJKW2A6","message": "<5>Apr 6 16:40:14 root: zhongguoren 7","elap_remote_ip": "192.168.113.195","timestamp": "2023-04-06 08:40:14.633"},"sort": [ - 1680770414633,"a6a328a0-d456-11ed-aa52-000c29f6b211"]},{ - "_index": "12_149","_type": "_doc","_id": "a73c3451-d456-11ed-aa52-000c29f6b211","_score": null,"_source": { - "elap_accounted_message_size": 140,"elap_source_input": "636c90d3246ca975ec999b24","streams": [ - "6969696969697379736c6f67","6969696969727379736c6f67"],"elap_remote_port": 36916,"elap_source_node": "5bb5d963-7fdd-4e2d-bfdf-a5069bb07097","source": "192.168.113.195","elap_message_id": "01GXAVJF0PXMNPGKVZ7YEJ1JNY","message": "<5>Apr 6 16:40:15 root: zhongguoren 8","elap_remote_ip": "192.168.113.195","timestamp": "2023-04-06 08:40:15.637"},"sort": [ - 1680770415637,"a73c3451-d456-11ed-aa52-000c29f6b211"]},{ - "_index": "12_149","_type": "_doc","_id": "a7dfc750-d456-11ed-aa52-000c29f6b211","_score": null,"_source": { - "elap_accounted_message_size": 140,"elap_source_input": "636c90d3246ca975ec999b24","streams": [ - "6969696969697379736c6f67","6969696969727379736c6f67"],"elap_remote_port": 42778,"elap_source_node": "5bb5d963-7fdd-4e2d-bfdf-a5069bb07097","source": "192.168.113.195","elap_message_id": "01GXAVJG26BRZG09JSSA96S329","message": "<5>Apr 6 16:40:16 root: zhongguoren 9","elap_remote_ip": "192.168.113.195","timestamp": "2023-04-06 08:40:16.708"},"sort": [ - 1680770416708,"a7dfc750-d456-11ed-aa52-000c29f6b211"]},{ - "_index": "12_149","_type": "_doc","_id": "a894bf71-d456-11ed-aa52-000c29f6b211","_score": null,"_source": { - "elap_accounted_message_size": 141,"elap_source_input": "636c90d3246ca975ec999b24","streams": [ - "6969696969697379736c6f67","6969696969727379736c6f67"],"elap_remote_port": 53090,"elap_source_node": "5bb5d963-7fdd-4e2d-bfdf-a5069bb07097","source": "192.168.113.195","elap_message_id": "01GXAVJH78H4GCQ44KNZQ1MQ0H","message": "<5>Apr 6 16:40:17 root: zhongguoren 10","elap_remote_ip": "192.168.113.195","timestamp": "2023-04-06 08:40:17.895"},"sort": [ - 1680770417895,"a894bf71-d456-11ed-aa52-000c29f6b211"]}]}
}

4.Search after二次查询

可以根据sort值带入到后续得search after中,以做到从某点进行再次查询。

GET index_1/_search
{"size": 10,"query": {"match": {"message": "zhongguoren"}},"search_after": [1680770417895,"a894bf71-d456-11ed-aa52-000c29f6b211"],"sort": [{"timestamp": "asc"},{"_id": "asc"}]
}

返回结果中,得到11-20条数据。


总结

我也尝试过,直接从16条的sort字段值进行查询,同样可以查询到17-20的值,所以,我们可以进行改造,默认仍然是10000条的max_result_window,兼顾小批量数据的查询和搜索,当查询从66页往后时,每次翻页或者跳页我们要能获取到超过10000的最后一条信息的id和时间戳,由此解决es深度查询翻页的问题。

明天找产品聊聊实现逻辑。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/24348.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2.13 Android ebpf非网络相关帮助函数API汇总(十二 本章完)

1.long bpf_user_ringbuf_drain(struct bpf_map *map, void *callback_fn, void *ctx, u64 flags) 描述:从指定的用户环形缓冲区中排出样本,并为每个此类样本调用提供的回调: long (*callback_fn)(struct bpf_dynptr *dynptr, void *ctx); 如果callback_fn返回0,帮助函数…

docker安装code-service在线开发vscode工具及node版本过低问题

docker安装code-service 拉去镜像 docker pull codercom/code-server创建项目存放映射路径 mkdir /data/code-service/project运行 这里不唯一&#xff0c;但注意密码 docker run -itd --name code-service -u root -p 1024:8080 -v /data/code-service/project:/home/cod…

Maven介绍-下载-安装-使用-基础知识

Maven介绍-下载-安装-使用-基础知识 Maven的进阶高级用法可查看这篇文章&#xff1a; Maven分模块-继承-聚合-私服的高级用法 文章目录 Maven介绍-下载-安装-使用-基础知识01. Maven1.1 初识Maven1.1.1 什么是Maven1.1.2 Maven的作用 02. Maven概述2.1 Maven介绍2.2 Maven模型…

hive编译报错整理

背景 最近在修hive-1.2.0的一个bug&#xff0c;需要修改后重新打包部署到集群&#xff0c;打包的时候报下面的错误&#xff0c;原因很简单&#xff0c;从远程仓库里面已经拉不到这个包了。 org.pentaho:pentaho-aggdesigner-algorithm:jar:5.1.5-jhyde was not found in http…

Unity进阶--通过PhotonServer实现联网登录注册功能(服务器端)--PhotonServer(二)

文章目录 Unity进阶--通过PhotonServer实现联网登录注册功能(服务器端)--PhotonServer(二)服务器端大体结构图BLL层&#xff08;控制层&#xff09;DAL层&#xff08;数据控制层&#xff09;模型层DLC 服务器配置类 发送消息类 以及消息类 Unity进阶–通过PhotonServer实现联网…

factoryBean.setTypeAliasesPackage()详解

示例代码 Bean public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) {SqlSessionFactoryBean factoryBean new SqlSessionFactoryBean();factoryBean.setDataSource(dataSource);factoryBean.setTypeAliasesPackage("com.itheima.domain");retu…

HCIP——STP

STP 一、STP概述二、二层环路带来的问题1、广播风暴问题2、MAC地址漂移问题3、多帧复制 三、802.1D生成树STP的BPDU1、配置BPDU2、RPC3、COST4、配置BPDU的工作过程5、TCN BPDU6、TCN BPDU的工作原理 四、STP的角色五、STP角色选举六、STP的接口状态七、接口状态的迁移八、STP的…

minio-分布式文件存储系统

minio-分布式文件存储系统 minio的简介 MinIO基于Apache License v2.0开源协议的对象存储服务&#xff0c;可以做为云存储的解决方案用来保存海量的图片&#xff0c;视频&#xff0c;文档。由于采用Golang实现&#xff0c;服务端可以工作在Windows,Linux, OS X和FreeBSD上。配置…

没有jodatime,rust里怎么将字符串转为日期呢?

关注我&#xff0c;学习Rust不迷路&#xff01;&#xff01; 在 Rust 中&#xff0c;有多种方法可以在时间和字符串之间进行转换。以下是五种常见的方式&#xff1a; 1. 使用 chrono 库进行转换&#xff1a; use chrono::{NaiveDateTime, DateTime, Utc, TimeZone};fn main(…

Mysql函数

MySQL -函数 常用字符串函数SELECT... 函数 功能 CONCAT&#xff08;S1&#xff0c;S2....Sn&#xff09; 字符串拼接 LOWER&#xff08;str&#xff09; 将字符串str全部改成小写 UPPER(str) 将字符串str全部改成大写 LPAD(str,n,pad) 左填充&#xff0c;用字符串pa…

实验5-1 使用函数计算两个复数之积 (10 分)

本题要求现一个函数计算两个复数之积。 函数接口定义&#xff1a; double result_real, result_imag; void complex_prod( double x1, double y1, double x2, double y2 ); 其中用户传入的参数为两个复数x1y1i和x2y2i&#xff1b;函数complex_prod应将计算结果的实部存放在全局…

线程间的同步、如何解决线程冲突与死锁

一、线程同步概念&#xff1a; 线程同步是指在多线程编程中&#xff0c;为了保证多个线程之间的数据访问和操作的有序性以及正确性&#xff0c;需要采取一些机制来协调它们的执行。在多线程环境下&#xff0c;由于线程之间是并发执行的&#xff0c;可能会出现竞争条件&#xf…

【WebRTC---源码篇】(三:一)音频轨

音频轨的创建时序在Conductor::AddTracks()中 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(peer_connection_factory_->CreateAudioTrack(kAudioLabel, peer_connection_factory_->CreateAudioSource(cricket::AudioOptions()))); 通过代码我们…

el-upload批量手动上传,并用form表单校验上传文件

手动上传设置:auto-upload"false" <el-formref"formData"class"formWidth":model"formData"label-width"120px":rules"rules"><el-form-itemlabel"数据"class"uploadClass"required…

RadioButton基本使用

作用&#xff1a;单选框&#xff0c;一般用于设置或者选择某项任务。 常用属性&#xff1a; 常用事件&#xff1a; 选中事件 后台代码&#xff1a; private void radioButton1_CheckedChanged(object sender, EventArgs e){if (radioButton1.Checked){MessageBox.Show(radioB…

AcWing 4310:树的DFS ← vector、auto、邻接表

【题目来源】https://www.acwing.com/problem/content/description/4313/【题目描述】 给定一棵 n 个节点的树。 节点的编号为 1∼n&#xff0c;其中 1 号节点为根节点&#xff0c;每个节点的编号都大于其父节点的编号。 现在&#xff0c;你需要回答 q 个询问。 每个询问给定两…

电脑ADB连接手机的方式通过网络无法adb连接手机的问题(已解决)

首先电脑要下载adb工具&#xff0c;将压缩包解压到C盘&#xff1a;https://download.csdn.net/download/qq_43445867/87975072 1、使用USB线连接 打开手机USB调试&#xff1b;PC端安装手机USB驱动。 1.打开DOS命令窗口&#xff0c;进入adb文件夹,输入adb.exe devices回车列出设…

用shell实现MySQL分库分表操作

#!/bin/bash mysql_cmd-uroot -p123 #定义变量保存密码 exclude_dbinformation_schema|performance_schema|sys #数据库 bak_path/backup/db #备份路径 mysql ${mysql_cmd} -e show databases -N | egrep -v "${exclude_db}" > dbname while read line do …

企业内网终端安全无客户端准入控制技术实践

终端无代理/无客户端准入控制技术因其良好的用户体验而倍受创新企业的青睐。无代理/无客户端准入控制技术&#xff0c;顾名思义&#xff0c;是一种在网络中对终端实施访问控制的方法&#xff0c;无需依赖特定的客户端软件。 不同于银行、医院等传统行业的终端准入控制需求&…

Kubernetes(K8s)从入门到精通系列之八:部署K8s对软件、硬件、网络通信的要求

Kubernetes K8s从入门到精通系列之八:部署K8s对软件、硬件、网络通信的要求 一、系统要求二、K8s集群网络通信要求一、系统要求 K8s系统由一组可执行程序组成,用户可以通过K8s在GitHub的项目网站下载编译好的二进制文件或镜像文件,或者下载源码并自行将其编译为二进制文件。…