Custom RequestOptions
# Set RequestOptions
The built-in framework uses the default RequestOptions of RestHighLevelClient, that is, RequestOptions.DEFAULT. In most scenarios, it is OK to use the default RequestOptions. However, there are very few personalized usage scenarios that require personalized settings. Meet business needs. For example, when querying some oversized fields, an error message appears: "entity content is too long [168583249] for the configured buffer limit [104857600]". At this time, you can increase the buffer size by customizing RequestOptions.
API
//Set the RequestOptions of the current mapper. After setting, it will permanently reside in the jvm cache. Subsequent CRUD will use this RequestOptions and will only become invalid after restarting the project.
Boolean setRequestOptions(RequestOptions requestOptions);
2
##use
@Test
public void testSetRequestOptions() {
// This case is for reference only. It can be customized and expanded according to business needs.
RequestOptions.Builder options = RequestOptions.DEFAULT.toBuilder();
options.setHttpAsyncResponseConsumerFactory(new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(4 * 104857600));
final RequestOptions requestOptions = options.build();
documentMapper.setRequestOptions(requestOptions);
}
2
3
4
5
6
7
8
Warm reminder
If not set, the default RequestOptions.DEFAULT will be used. If set, it will take effect globally for the current mapper. If there are multiple mappers, they can be set as needed according to the business scenario.