<p dir="auto">There does not appear to be a way to replicate this feature with the current aggregation API.</p>
<p dir="auto">have a web service, where every time a button is pressed from UI, it connects to elastic search and fires a query. This is the code which is executed every time. The issue is that after a while, intermittently, the UI hangs.</p>
<p dir="auto">private static final String CONFIG_CLUSTER_NAME = "cluster.name";</p>
<p dir="auto">private static final String CLUSTER_NAME = "sample_es";<br>
private static final String[] transportAddress = {<br>
//Machine details<br>
};</p>
<p dir="auto">private static final int transportPort = 9300;</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    public static Client initClient(){
    settings = ImmutableSettings.settingsBuilder().put(CONFIG_CLUSTER_NAME, CLUSTER_NAME).build();

    Client client = new TransportClient(settings);
    for (int i=0 ; i &lt; transportAddress.length-1 ; i++){
        ((TransportClient)client).addTransportAddress(new InetSocketTransportAddress(transportAddress[i], transportPort));
    }
    logger.info(&quot;TransportClient Created&quot;); 
    return client;  "><pre class="notranslate"><code class="notranslate">    public static Client initClient(){
    settings = ImmutableSettings.settingsBuilder().put(CONFIG_CLUSTER_NAME, CLUSTER_NAME).build();

    Client client = new TransportClient(settings);
    for (int i=0 ; i &lt; transportAddress.length-1 ; i++){
        ((TransportClient)client).addTransportAddress(new InetSocketTransportAddress(transportAddress[i], transportPort));
    }
    logger.info("TransportClient Created"); 
    return client;  
</code></pre></div>
<p dir="auto">}</p>
<p dir="auto">public static int query( String query) throws Exception<br>
{<br>
Client client = null;<br>
try{</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        client = initClient();

        //Query search code

}catch(Exception e){
        e.printStackTrace();
}finally{
    if(client != null){
        client.close();
        logger.info(&quot;TransportClient Closed&quot;);
    }
}
    return result_count;"><pre class="notranslate"><code class="notranslate">        client = initClient();

        //Query search code

}catch(Exception e){
        e.printStackTrace();
}finally{
    if(client != null){
        client.close();
        logger.info("TransportClient Closed");
    }
}
    return result_count;
</code></pre></div>
<p dir="auto">}</p>
<p dir="auto">Whenever we restart the tomcat server, this is the error message we are seeing in logs. How should we fix this?</p>
<p dir="auto">[org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom$1](value<br>
[org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom$1@5838ce3e]) and a value of type<br>
[org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom](value<br>
[org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom@796c75b1]) but failed to remove it<br>
when the web application was stopped. This is very likely to create a memory leak.</p>