您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。