zoukankan      html  css  js  c++  java
  • 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一致。

  • 相关阅读:
    搭建vue项目脚手架
    vue项目中的iconfont图标下载及配置
    vue-awesome-swiper 轮播图的使用
    IDEA自动生成Mapper和实体文件
    云服务器通过IP如何访问项目
    社保,步入社会的第一步
    Memcached安装与启动
    IDEA提示非法字符,你不懂的UTF-8
    MyEclipse导入eclipse的web项目,将WebRoot切换为WebContent
    Myeclipse2017删除tomcat后,项目全部报错的解决办法
  • 原文地址:https://www.cnblogs.com/ernst/p/12819177.html
Copyright © 2011-2022 走看看