为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

冉冉说 2021-08-25 16:27:17
如何使用 Elasticsearch RestHighLevelClient 添加查询参数?例如:/_search/q=style:SB我在SearchRequest课堂上没有看到这个选项。
查看完整描述

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();

    }


查看完整回答
反对 回复 2021-08-25
  • 1 回答
  • 0 关注
  • 729 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号