JavaAPI操作es出现NoNodeAvailableException[None of the configured nodes are available:{192.168.37.111}

NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{9FWCcWUvQVCwQp4VGbT6rA}{192.168.37.111}{192.168.37.111:9300}, {#transport#-2}{VGaN7CMWTqaM9fpnhSLv0A}{192.168.37.112}{192.168.37.112:9300}, {#transport#-3}{iumH2hK9Q7ah_2_KflE6Pw}{192.168.37.113}{192.168.37.113:9300}]
]

操作elasticsearch的JavaApi出错
原因 Settings settings = Settings.builder().put(“cluster.name”, “my-elk”).build();
我的es集群名称配置时在安装目录下的/usr/local/elasticsearch-6.5.3/config/elasticsearch.yml
cluster-name my-elk
写成myelk了
写成与配置文件一致就对了
还有在这里插入图片描述

package com.qf.test.demo1_env;

import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Created by Shi shuai RollerQing on 2019/11/20 16:31
 */
public class TestEnv {
    //TransportClient实例 用于访问远程集群
    private TransportClient client;

    private final String INDEX = "bigdata";
    private final String TYPE = "product";
    @Before
    public void init() throws UnknownHostException {
        Settings settings = Settings.builder().put("cluster.name", "my-elk").build();
        client = new PreBuiltTransportClient(settings);
        client.addTransportAddress(new TransportAddress(InetAddress.getByName("hadoop01"), 9300));
        client.addTransportAddress(new TransportAddress(InetAddress.getByName("hadoop02"), 9300));
        client.addTransportAddress(new TransportAddress(InetAddress.getByName("hadoop03"), 9300));

    }

    @Test
    public void testEnv(){

        //测试1:
        System.out.println("clinet = " + client);

        System.out.println("--------------------------------->>>>>>");

        //测试2:
        //读取索引库bigdata中的type之product中的id值为1的索引信息
        GetResponse response = client.prepareGet(INDEX, TYPE, "1").get();
        System.out.println("返回的结果是:" + response);
        System.out.println("返回的source是:" + response.getSourceAsString());



    }

    @After
    public void cleanUp(){
        if(client != null){
            client.close();
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值