Elasticsearch Transport client connection


Akshay Bijawe

I am building a Search Web Application with a servlet connected to Elasticsearch. I have a question about Elasticsearch 's shipping module . I am using TransportClient in a class implementing ServletContextListener to open a connection to Elasticsearch. Following is the code of ElasticsearchServletContextListener class.

public class ElasticsearchContextListener implements ServletContextListener {

  @Override
  public void contextInitialized(ServletContextEvent servletContextEvent) {
    System.out.println("Starting up!");

    try {
      Client client = TransportClient.builder().build().addTransportAddress(
          new InetSocketTransportAddress(InetAddress.getByName("IP-address"),9300));
    //Storing the client connection in a static variable
      Parameters.setESclient(client);

    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

  }

  @Override
  public void contextDestroyed(ServletContextEvent servletContextEvent) {
    Parameters.getESclient().close();
    System.out.println("Shutting down!");
  }
}

Now, whenever the user searches for a query, it uses the same "client" connection that was initialized in the ServletContextListener class. Can a client connection handle multiple requests at the same time? Or does each user need a separate client connection to query elasticsearch? thank you for your help.

Andrei Stefan

The Clientinstance is able to handle multiple calls and handle multiple threads. Also, you should only have one instance of Client because creating one is expensive.

Related


Secure connection using transport client

St. Kaidal Need to connect to secure elasticsearch with https authentication using transport client in java code. I have the user id and password to connect, but need an example of how we do it? I am using elastic search 5.6.0. I'm looking for xpack and shelf

Secure connection using transport client

St. Kaidal Need to connect to secure elasticsearch with https authentication using transport client in java code. I have the user id and password to connect, but need an example of how we do it? I am using elastic search 5.6.0. I'm looking for xpack and shelf

elasticsearch transport client with url path

Shakul Hameed My elasticsearch wrapped in tomcat using transport software is up and running in a cluster of 20 computers on a specific path /essearch. I have load balancer before clustering with dns, so I use www.dns.com/essearch/ to access elastic search Now

elasticsearch transport client with url path

Shakul Hameed My elasticsearch wrapped in tomcat using transport software is up and running in a cluster of 20 computers on a specific path /essearch. I have load balancer before clustering with dns, so I use www.dns.com/essearch/ to access elastic search Now

How to handle transport errors in elasticsearch python client?

Hans I'm uploading a pandas dataframe to Elastic (using elasticsearch==6.3.1), it works fine if the dataframe size is less than 100MB, I'm using the solution from How to export pandas data to Elasticsearch ? def rec_to_actions(df): for record in df.to_dict

How to handle transport errors in elasticsearch python client?

Hans I'm uploading a pandas dataframe to Elastic (using elasticsearch==6.3.1), it works fine if the dataframe size is less than 100MB, I'm using the solution from How to export pandas data to Elasticsearch ? def rec_to_actions(df): for record in df.to_dict

Specify fields using the Elasticsearch Transport client

Tula Is there a way to specify the fields that ES returns via the transport client (specifically using the BoolQueryBuilder)? Using the REST API, this seems easy, for example, can I specify the result field in the elasticsearch query? But not sure how to use t

How to handle transport errors in elasticsearch python client?

Hans I'm uploading a pandas dataframe to Elastic (using elasticsearch==6.3.1), it works fine if the dataframe size is less than 100MB, I'm using the solution from How to export pandas data to Elasticsearch ? def rec_to_actions(df): for record in df.to_dict

How to connect to ElasticSearch using Java transport client?

Manolis Karamanis I am following ElasticSearch documentation on Java Client. I have ElasticSearch started and can interact with it using the Rest API. I want to use a Java client, so far I have a body like this: public class TestElastic { public static void m

How to handle transport errors in elasticsearch python client?

Hans I'm uploading a pandas dataframe to Elastic (using elasticsearch==6.3.1), it works fine if the dataframe size is less than 100MB, I'm using the solution from How to export pandas data to Elasticsearch ? def rec_to_actions(df): for record in df.to_dict

How to handle transport errors in elasticsearch python client?

Hans I'm uploading a pandas dataframe to Elastic (using elasticsearch==6.3.1), it works fine if the dataframe size is less than 100MB, I'm using the solution from How to export pandas data to Elasticsearch ? def rec_to_actions(df): for record in df.to_dict

How to handle transport errors in elasticsearch python client?

Hans I'm uploading a pandas dataframe to Elastic (using elasticsearch==6.3.1), it works fine if the dataframe size is less than 100MB, I'm using the solution from How to export pandas data to Elasticsearch ? def rec_to_actions(df): for record in df.to_dict

Specify fields using the Elasticsearch Transport client

Tula Is there a way to specify the fields that ES returns via the transport client (specifically using the BoolQueryBuilder)? Using the REST API, this seems easy, for example, can I specify the result field in the elasticsearch query? But not sure how to use t

Import org.elasticsearch.transport.client could not be resolved

Aaron: I am trying to use Elasticsearch in Java. I have Elasticserach version 7.0.1 installed. Next line: import org.elasticsearch.transport.client.*; produces a compile error: Import org.elasticsearch.transport.client could not be resolved Even though I can

Import org.elasticsearch.transport.client could not be resolved

Aaron: I am trying to use Elasticsearch in Java. I have Elasticserach version 7.0.1 installed. Next line: import org.elasticsearch.transport.client.*; produces a compile error: Import org.elasticsearch.transport.client could not be resolved Even though I can

Import org.elasticsearch.transport.client could not be resolved

Aaron: I am trying to use Elasticsearch in Java. I have Elasticserach version 7.0.1 installed. Next line: import org.elasticsearch.transport.client.*; produces a compile error: Import org.elasticsearch.transport.client could not be resolved Even though I can