自定义RequestOptions
# 设置RequestOptions
框架内置默认使用的是RestHighLevelClient的默认RequestOptions,即RequestOptions.DEFAULT,在大多数场景下,使用默认的RequestOptions是OK的,但是有极个别个性化的使用场下,需要对其进行个性化设置,才能满足业务需求. 例如查询某些超大字段时报错: "entity content is too long [168583249] for the configured buffer limit [104857600]",此时就可以通过自定义RequestOptions来调大缓冲区.
API
// 设置当前mapper的RequestOptions 设置后永驻jvm缓存,后续CRUD均使用该RequestOptions, 重启项目才失效
Boolean setRequestOptions(RequestOptions requestOptions);
1
2
2
##使用
@Test
public void testSetRequestOptions() {
// 此案例仅供参考,实际可按业务需要自定义拓展
RequestOptions.Builder options = RequestOptions.DEFAULT.toBuilder();
options.setHttpAsyncResponseConsumerFactory(new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(4 * 104857600));
final RequestOptions requestOptions = options.build();
documentMapper.setRequestOptions(requestOptions);
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
温馨提示
不设置则使用默认的RequestOptions.DEFAULT,设置后则针对当前mapper全局生效,如有多个mapper,可按业务场景按需设置
帮助我们改善此文档 (opens new window)
上次更新: 2024/05/18