• ElasticSearch java客户端更新时出现的错误:NoNodeAvailableException[None of the configured nodes are available


    // 存放html文件的目录
    	public static String DATA_DIR = "F:\data";
    
    	public static Client client;
    
    	static {
    		Settings settings = Settings.settingsBuilder().put("cluster.name", "bd-es").build();
    		try {
    			client = TransportClient.builder().settings(settings).build()
    					.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("es"), 19301))
    					.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("es"), 19302))
    					.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("es"), 19303));
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    /**
    	 * admin():管理索引库的。client.admin().indices()
    	 * 
    	 * 索引数据的管理:client.prepare
    	 * 
    	 */
    	@Test
    	public void createIndex() throws Exception {
    		IndicesExistsResponse resp = client.admin().indices().prepareExists("myindex").execute().actionGet();
    		if (resp.isExists()) {
    			client.admin().indices().prepareDelete("myindex").execute().actionGet();
    		}
    		client.admin().indices().prepareCreate("myindex").execute().actionGet();
    
    		new XContentFactory();
    
    		XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("htmlbean")
    				.startObject("properties").startObject("title").field("type", "string").field("store", "yes")
    				.field("analyzer", "ik_max_word").field("search_analyzer", "ik_max_word").endObject()
    				.startObject("content").field("type", "string").field("store", "yes").field("analyzer", "ik_max_word")
    				.field("search_analyzer", "ik_max_word").endObject()
    				// .startObject("url").field("type", "string")
    				// .field("store", "yes").field("analyzer", "ik_max_word")
    				// .field("search_analyzer", "ik_max_word").endObject()
    				.endObject().endObject().endObject();
    		PutMappingRequest mapping = Requests.putMappingRequest("myindex").type("htmlbean").source(builder);
    		client.admin().indices().putMapping(mapping).actionGet();
    
    	}
    

    改正两点后解决问题,
    一处是用19301端口 而不是19201.19201端口只是HTTP端口。
    第二处是"cluster.name", “bd-es” 要和config/elasticsearch.yml 配置的cluster.name一致。

  • 相关阅读:
    常用功能测试点的测试用例
    如何设计功能测试测试用例
    管理小原则
    政党提供的公共产品是其存在的依据
    为什么人是根本?
    学问总分类
    和孩子沟通的开头常用语
    教育的核心对象是心中的那枚种子
    用目标激发动力,用计划控制落实,用梳理总结进行提高
    要想影响孩子第一位的是保证沟通畅通
  • 原文地址:https://www.cnblogs.com/ernst/p/12819177.html
Copyright © 2020-2023  润新知