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.


Relevant Logs or Screenshots:
TransportClient transportClient = new PreBuiltTransportClient(,

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(, 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( 
	at org.elasticsearch.common.xcontent.XContentParserUtils.parseTypedKeysObject(  
	at org.elasticsearch.client.RestHighLevelClient.parseEntity( 
	at org.elasticsearch.client.RestHighLevelClient.lambda$performRequestAndParseEntity$12( 
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest( 
	at org.elasticsearch.client.RestHighLevelClient.performRequest(  
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity( 

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(, CustomPluginClass.class);