如何使用 Elasticsearch RestHighLevelClient 添加查询参数?

如何使用 Elasticsearch RestHighLevelClient 添加查询参数?

例如:

/_search/q=style:SB

我在SearchRequest课堂上没有看到这个选项。


冉冉说
浏览 721回答 1
1回答

狐的传说

我认为你不能在RestHighLevelClient 中添加查询参数,因为它的主要目标是公开 API 特定的方法,这些方法接受请求对象作为参数并返回响应对象。由于RestHighLevelClient建立在 Low Level REST Client 之上,您可以使用它来添加查询参数。RestHighLevelClient client = new RestHighLevelClient(&nbsp; &nbsp; &nbsp; &nbsp; RestClient.builder(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new HttpHost("localhost", 9200, "http"),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 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,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HttpEntity entity, HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Header... headers) throws IOException {&nbsp; &nbsp; &nbsp; &nbsp; SyncResponseListener listener = new SyncResponseListener(maxRetryTimeoutMillis);&nbsp; &nbsp; &nbsp; &nbsp; performRequestAsync(method, endpoint, params, entity, httpAsyncResponseConsumerFactory, listener, headers);&nbsp; &nbsp; &nbsp; &nbsp; return listener.get();&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java