RestHighLevelClient - How to use custom plugins?

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):

OpenSearch 2.5

Describe the issue:

I am working towards migrating from TransportClient to RestHighLevelClient.
We use custom plugin which is supported in RestHighLevelClient as below. But, I am not able to find ways to support custom plugin with RestHighLevelClient, can anybody help? Below is my code.

Configuration:

Relevant Logs or Screenshots:
TransportClient transportClient = new PreBuiltTransportClient(settings.build(),
CustomPluginClass.class);

Need to migrate from TransportClient to RestHighLevelClient.

Hello @hr89 - welcome to the OpenSeach community - we’re glad you’re here.

Does this blog post help?

Hi @kris
Thanks for your reply. I did go through this blog post.
However, I am looking for registering my custom plugin with the RestHighLevelClient.
As mentioned below in the PreBuiltTransportClient we have a constructor which accepts Plugin as parameter, below TransportClient transportClient = new PreBuiltTransportClient(settings.build(), CustomPluginClass.class);

But I could not find any such provision in RestHighLevelClient, can you help here?

@dadoonet Can you please help here?

I think you don’t need to register a plugin here. Why would you need to do that?

We have our custom aggregation plugin that we use, it has custom response fields for which we are getting the below exception, so clearly our plugin code is not trigerred which is capable of parsing the response.

Caused by: org.elasticsearch.common.xcontent.NamedObjectNotFoundException: [1:194] unknown field [collect]
	at org.elasticsearch.common.xcontent.NamedXContentRegistry.parseNamedObject(NamedXContentRegistry.java:156) 
	at org.elasticsearch.common.xcontent.support.AbstractXContentParser.namedObject(AbstractXContentParser.java:435) 
	at org.elasticsearch.common.xcontent.XContentParserUtils.parseTypedKeysObject(XContentParserUtils.java:172)  
	at org.elasticsearch.search.aggregations.Aggregations.fromXContent(Aggregations.java:157)  
	at org.elasticsearch.action.search.SearchResponse.innerFromXContent(SearchResponse.java:369)  
	at org.elasticsearch.action.search.SearchResponse.fromXContent(SearchResponse.java:325)  
	at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:2228) 
	at org.elasticsearch.client.RestHighLevelClient.lambda$performRequestAndParseEntity$12(RestHighLevelClient.java:1845) 
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1928) 
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1877)  
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1845) 
	at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:1088) 

Please note that prior to this we used TransportClient which we initialized like below (with Plugin class name) and it worked perfectly. So, I am looking for something similar for RestHighLevelClient.

TransportClient transportClient = new PreBuiltTransportClient(settings.build(), CustomPluginClass.class);