博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NoNodeAvailableException[None of the configured nodes are available
阅读量:5140 次
发布时间:2019-06-13

本文共 2846 字,大约阅读时间需要 9 分钟。

可能的原因:

1、项目引用的ES版本和ES服务的版本不一样;

2、端口不正确,tcp访问端口是9300;

3、cluster.name不正确,可以通过访问http://localhost:9200/查看ES服务下的cluster.name;

4、ES服务没启动;

简单demo:

import java.net.InetAddress;import java.net.UnknownHostException;import org.elasticsearch.action.search.SearchRequestBuilder;import org.elasticsearch.action.search.SearchResponse;import org.elasticsearch.client.transport.TransportClient;import org.elasticsearch.common.settings.Settings;import org.elasticsearch.common.transport.InetSocketTransportAddress;import org.elasticsearch.index.query.QueryBuilders;import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;import org.elasticsearch.transport.client.PreBuiltTransportClient;public class ElasticDemo {	 //测试demo		@SuppressWarnings({ "resource", "unchecked" })		public static void main(String[] aa) throws UnknownHostException {	    	TransportClient client = null;	    	Settings esSettings = Settings.builder()	                .put("cluster.name", "elasticsearch") //设置ES实例的名称	                .build();	        client = new PreBuiltTransportClient(esSettings)	                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));	        System.out.println("ElasticsearchClient 连接成功");	    	//	    	BulkRequestBuilder bulkRequest = client.prepareBulk();//	        try {//				bulkRequest.add(client.prepareIndex("ko", "test", "14")//				        .setSource(jsonBuilder()//				                .startObject()//				                .field("tableId", "14")//				                .field("title", "tetstcccfffffccccccccccc")//				                .field("content", "ttttttttfffffffttttttttttt")//				                .endObject()//				        )//				);//			} catch (IOException e) {//				e.printStackTrace();//			}//	        BulkResponse bulkResponse = bulkRequest.get();//	        if (bulkResponse.hasFailures()) {//	            System.out.println("失败:" + bulkResponse.toString());//	        }//	        System.out.println("操作成功");	    		        HighlightBuilder highlightBuilder = new HighlightBuilder().field("title").requireFieldMatch(true);	        highlightBuilder.preTags("");	        highlightBuilder.postTags("");	        highlightBuilder.boundaryMaxScan(4);	        	        SearchRequestBuilder searchRequestBuilder = client.prepareSearch("ko");	//可以是多个index	        //searchRequestBuilder.setQuery(QueryBuilders.termQuery("title", "ffff"));	//精确查询	        searchRequestBuilder.setQuery(QueryBuilders.wildcardQuery("title", "*文 el*"));	//模糊查询	        searchRequestBuilder.setFrom(0);	        searchRequestBuilder.setSize(2);	        searchRequestBuilder.highlighter(highlightBuilder);	        SearchResponse response = searchRequestBuilder.get();	        System.out.println(response);	    }		}

  

posted on
2019-05-31 17:05 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/yanketao/p/10956299.html

你可能感兴趣的文章
oracle 创建暂时表
查看>>
201421410014蒋佳奇
查看>>
Xcode5和ObjC新特性
查看>>
LibSVM for Python 使用
查看>>
Centos 7.0 安装Mono 3.4 和 Jexus 5.6
查看>>
CSS属性值currentColor
查看>>
java可重入锁reentrantlock
查看>>
浅谈卷积神经网络及matlab实现
查看>>
解决ajax请求cors跨域问题
查看>>
《收获,不止Oracle》pdf
查看>>
LinkedList<E>源码分析
查看>>
Real-Time Rendering 笔记
查看>>
如何理解HTML结构的语义化
查看>>
Activity之间的跳转:
查看>>
实验四2
查看>>
Android现学现用第十一天
查看>>
多路复用
查看>>
Python数据可视化之Pygal(雷达图)
查看>>
Java学习笔记--字符串和文件IO
查看>>
转 Silverlight开发历程—(画刷与着色之线性渐变画刷)
查看>>