1 回答

TA貢獻1804條經驗 獲得超3個贊
我認為你不能在RestHighLevelClient 中添加查詢參數,因為它的主要目標是公開 API 特定的方法,這些方法接受請求對象作為參數并返回響應對象。
由于RestHighLevelClient建立在 Low Level REST Client 之上,您可以使用它來添加查詢參數。
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost("localhost", 9200, "http"),
new HttpHost("localhost", 9201, "http")));
使用它從 RestHighLevelClient 獲取低級客戶端:
RestClient lowLevelClient = client.getLowLevelClient();
低級 REST 客戶端有一個方法 performRequest 接受查詢參數:
lowLevelClient.performRequest(method, endpoint, params, entity, null);
方法說明:
public Response performRequest(String method, String endpoint, Map<String, String> params,
HttpEntity entity, HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory,
Header... headers) throws IOException {
SyncResponseListener listener = new SyncResponseListener(maxRetryTimeoutMillis);
performRequestAsync(method, endpoint, params, entity, httpAsyncResponseConsumerFactory, listener, headers);
return listener.get();
}
添加回答
舉報