Elasticsearch server cannot connect with java api

(salma) #1

J have a spring boot application , I have in elasticsaerch connect in localhost:9200 but i need to connect the spring boot application to elasticsearch server with the transport client but spring boot application connect to node client and not connect to server.
This is my Elasticsearch Configuration:

public class EsConfig {

    private String EsHost;

    private int EsPort;

    private String EsClusterName;

    public Client client() {

    		Settings esSettings = Settings.builder()
            		.put("cluster.name", "mkyong-cluster").build();
            TransportClient client = new PreBuiltTransportClient(esSettings).addTransportAddress(
    				  new InetSocketTransportAddress(InetAddress.getByName(EsHost), EsPort));
            return client;
    	}catch(Exception e){
		return null;
        return TransportClient.builder()
				  new InetSocketTransportAddress(InetAddress.getByName(EsHost), EsPort));

    public ElasticsearchOperations elasticsearchTemplate() throws Exception {
        return new ElasticsearchTemplate(client());

This is my application.properties:
spring.data.elasticsearch.properties.clustername = mkyong-cluster
spring.data.elasticsearch.properties.host = localhost
spring.data.elasticsearch.properties.port = 9300

This is my response in console:

client.type = node
cluster.name = elasticsearch
clustername = mkyong-cluster
host = localhost
http.enabled = false
name = Mondo
node.local = true
path.home = target/elastic-embedded
path.logs = C:/Project/workspace/workspace1/backend-project/target/elastic-embedded/logs
port = 9300
transport.tcp.connect_timeout = 60s

I need to connect in elasticsearch server but does not exist in localhost:9200 but he connect to node local and client type node not transport
Can help please.

(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.