这期内容当中小编将会给大家带来有关Elasticsearch Java Client版本区别及起步是什么,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
简单总结:
如果服务端是5.6以下的,选择相同版本的TransportClient,避免一些API服务端不支持
如果服务端是5.6以上的,选择相同版本的RestClient
5.6及之前的版本:
// on startup Client client = TransportClient.builder().build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300)) .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300)); // on shutdown client.close();
6.0及之后的版本:
// on startup TransportClient client = new PreBuiltTransportClient(Settings.EMPTY) .addTransportAddress(new TransportAddress(InetAddress.getByName("host1"), 9300)) .addTransportAddress(new TransportAddress(InetAddress.getByName("host2"), 9300)); // on shutdown client.close();
SearchResponse response = client.prepareSearch("index1", "index2") .setTypes("type1", "type2") .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setQuery(QueryBuilders.termQuery("multi", "test")) // Query .setPostFilter(QueryBuilders.rangeQuery("age").from(12).to(18)) // Filter .setFrom(0).setSize(60).setExplain(true) .get();
// Java Low Level REST Client RestClient lowLevelRestClient = RestClient.builder( new HttpHost("localhost", 9200, "http"), new HttpHost("localhost", 9201, "http")).build(); // Java High Level REST Client RestHighLevelClient client = new RestHighLevelClient(lowLevelRestClient);
SearchRequest searchRequest = new SearchRequest(); searchRequest.source(sourceBuilder); SearchResponse searchResponse = client.search(searchRequest);
上述就是小编为大家分享的Elasticsearch Java Client版本区别及起步是什么了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。