日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Hadoop -- ES -- CURD

發布時間:2024/9/5 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Hadoop -- ES -- CURD 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.獲取ES連接

package com.ciic.history.common;import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress;import java.net.InetAddress; import java.net.UnknownHostException;public class DaoUtilL {private static TransportClient clientL = null;private DaoUtilL(){};public static TransportClient getClientL() {try {if (null != clientL) {return clientL;}Settings settings = Settings.settingsBuilder().put("cluster.name", "search1").put("transport.tcp.compress", true).build();InetSocketTransportAddress address1 = new InetSocketTransportAddress(InetAddress.getByName("192.168.43.249"), 9300);InetSocketTransportAddress address2 = new InetSocketTransportAddress(InetAddress.getByName("192.168.43.250"), 9300);InetSocketTransportAddress address3 = new InetSocketTransportAddress(InetAddress.getByName("192.168.43.251"), 9300);InetSocketTransportAddress address4 = new InetSocketTransportAddress(InetAddress.getByName("192.168.43.252"), 9300);TransportAddress[] addressArr = {address1, address2, address3, address4};clientL = TransportClient.builder().settings(settings).build().addTransportAddresses(addressArr);return clientL;} catch (Exception e) {return null;}} }

?

2.CURD操作

@Overridepublic JsonEntity queryCustomerPreview(int page, int rows) {TransportClient clientL = DaoUtilL.getClientL();SearchRequestBuilder builder = clientL.prepareSearch();builder.setIndices("esinner_limecustomerpreview_index").setTypes("xian").addSort("imscustomername", SortOrder.ASC).setFrom((page-1)*rows).setSize(rows);SearchResponse response = builder.get();SearchHit[] searchHits = response.getHits().getHits();ArrayList arrayList = new ArrayList();for(int i = 0; i < searchHits.length; i++) {arrayList.add(searchHits[i].getSource());}//查詢總記錄數totalSearchResponse totalResponse = clientL.prepareSearch().setIndices("esinner_limecustomerpreview_index").setSearchType(SearchType.COUNT).setSize(0).get();long length = response.getHits().totalHits();JsonEntity entity = new JsonEntity();entity.setTotal(length);entity.setRows(arrayList);return entity;}

-- -- -- -- -- --?

@Overridepublic JsonEntity customerPreviewSearch(EsinnerLimeCustomerPreviewIndex customerPreview, int page, int rows) {TransportClient clientL = DaoUtilL.getClientL();SearchRequestBuilder searchRequestBuilder = clientL.prepareSearch();searchRequestBuilder.setIndices("esinner_limecustomerpreview_index").setTypes("xian").setSearchType(SearchType.DEFAULT).setFrom((page-1)*rows).setSize(rows);BoolQueryBuilder builder = QueryBuilders.boolQuery();boolean flag=true;if(StringUtils.isNotBlank(customerPreview.getImscustomername())){flag=false;builder.must(QueryBuilders.termQuery("imscustomername",customerPreview.getImscustomername()));}if(StringUtils.isNotBlank(customerPreview.getImscustomercode())){flag=false;builder.must(QueryBuilders.matchQuery("imscustomercode",customerPreview.getImscustomercode()));}if(flag==true){searchRequestBuilder.addSort("imscustomercode", SortOrder.ASC);}searchRequestBuilder.setQuery(builder);SearchResponse response = searchRequestBuilder.get();SearchHit[] searchHits = response.getHits().getHits();ArrayList arrayList = new ArrayList();for(int i = 0; i < searchHits.length; i++) {arrayList.add(searchHits[i].getSource());}SearchResponse totalResponse = clientL.prepareSearch().setIndices("esinner_limecustomerpreview_index").setSearchType(SearchType.COUNT).setSize(0).get();long length = response.getHits().totalHits();JsonEntity entity = new JsonEntity();entity.setTotal(length);entity.setRows(arrayList);return entity;}

-- -- -- -- -- --?

3.返回數據

啦啦啦

轉載于:https://www.cnblogs.com/ClassNotFoundException/p/7279871.html

總結

以上是生活随笔為你收集整理的Hadoop -- ES -- CURD的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。