中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

無錫做網(wǎng)站費(fèi)用北京百度推廣代理

無錫做網(wǎng)站費(fèi)用,北京百度推廣代理,自己做的網(wǎng)站可以有多個前端嗎,動態(tài)網(wǎng)站建設(shè)教程1 java操作ES方式 1.1 操作ES 9300端口(TCP) 但開發(fā)中不在9300進(jìn)行操作 ES集群節(jié)點(diǎn)通信使用的也是9300端口如果通過9300操作ES,需要與ES建立長連接 可通過引入spring-data-elasticsearch:transport-api.jar不在9300操作原因:1.springboot版本不同&…

1 java操作ES方式

1.1 操作ES 9300端口(TCP) 但開發(fā)中不在9300進(jìn)行操作
ES集群節(jié)點(diǎn)通信使用的也是9300端口如果通過9300操作ES,需要與ES建立長連接  可通過引入spring-data-elasticsearch:transport-api.jar不在9300操作原因:1.springboot版本不同,transport-api.jar不同,不能適配ES版本2.官方在7.x版本已經(jīng)不建議在9300操作ES,8以后會廢棄ES通過9300操作的jar包
1.2 操作ES 9200端口(HTTP) 優(yōu)選Elasticsearch-Rest-Client
通過9200對ES發(fā)送Http請求就可以了
1.使用第三方JestClient操作ES:更新慢
2.RestTemplate、HttpClient、OkHttp:發(fā)送HTTP請求,但如果操作ES一些DSL語句,需要自己封裝,麻煩
3.Elasticsearch-Rest-Client(elasticsearch-rest-high-level-client):官方RestClient,封裝了ES操作,API層次分明,上手簡單

2 整合

2.1引入elasticsearch-rest-high-level-client依賴
<!--elasticsearch-->
<dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-high-level-client</artifactId><version>7.4.2</version>
</dependency>
刷新Maven 會發(fā)現(xiàn)elasticsearch和elasticsearch-rest-client版本是7.17.4,并不是7.4.2

在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述

原因是因為springboot對ES版本做了管理,當(dāng)前springboot默認(rèn)整合spring-data-elasticsearch操作ES
修改版本問題
如果使用Maven進(jìn)行一個直接或間接繼承spring-boot-dependencies(比如spring-boot-starter-parent)的構(gòu)建,并想覆蓋一個特定的
第三方依賴版本,可以添加<properties>標(biāo)簽,并重寫第三方依賴版本
<properties><elasticsearch.version>7.4.2</elasticsearch.version>
</properties>
如果使用<scope>import</scope>,將spring-boot-dependencies添加到自己的dependencyManagement片段,
那么必須重新定義artifact而不是重寫第三方依賴版本
<dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>2.7.3</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>org.elasticsearch</groupId><artifactId>elasticsearch</artifactId><version>7.4.2</version></dependency><dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-client</artifactId><version>7.4.2</version></dependency></dependencies>
</dependencyManagement>
2.2 添加ES配置
@Configuration
public class ElasticsearchConfig {/*** 配置請求選項* 參考:https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.4/java-rest-low-usage-requests.html#java-rest-low-usage-request-options*/public static final RequestOptions COMMON_OPTIONS;static {RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();// builder.addHeader("Authorization", "Bearer " + TOKEN);// builder.setHttpAsyncResponseConsumerFactory(//         new HttpAsyncResponseConsumerFactory//                 .HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024));COMMON_OPTIONS = builder.build();}@Beanpublic RestHighLevelClient esRestClient() {
//        RestHighLevelClient highLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost("192.168.179.101", 9200, "Http"),
//                new HttpHost("192.168.179.101", 9201, "Http")));RestHighLevelClient highLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost("192.168.179.101", 9200, "Http")));return highLevelClient;}}
2.3 測試及驗證整合結(jié)果
@SpringBootTest
public class SearchApplicationTests {@Autowiredprivate RestHighLevelClient client;@Data@ToStringstatic class Account {private int account_number;private int balance;private String firstname;private String lastname;private int age;private String gender;private String address;private String employer;private String email;private String city;private String state;}/*** 在new_bank中搜索address中包含mill的所有人的年齡分布以及平均薪資*/@Testpublic void searchData() throws IOException {//1,創(chuàng)建檢索請求SearchRequest searchRequest = new SearchRequest();//1.1,指定檢索索引searchRequest.indices("new_bank");//1.2,構(gòu)造檢索條件SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();searchSourceBuilder.query(QueryBuilders.matchQuery("address", "Mill"));//1.2.1,按照年齡分布進(jìn)行聚合TermsAggregationBuilder ageAgg = AggregationBuilders.terms("ageAgg").field("age").size(10);searchSourceBuilder.aggregation(ageAgg);//1.2.2,計算平均薪資AvgAggregationBuilder avgBalance = AggregationBuilders.avg("avgBalance").field("balance");searchSourceBuilder.aggregation(avgBalance);System.out.println("檢索條件" + searchSourceBuilder);searchRequest.source(searchSourceBuilder);//2,執(zhí)行同步檢索SearchResponse searchResponse = client.search(searchRequest, ElasticsearchConfig.COMMON_OPTIONS);System.out.println("執(zhí)行檢索結(jié)果" + searchResponse);//3,提取命中結(jié)果hitsSearchHits hits = searchResponse.getHits();SearchHit[] hitsHits = hits.getHits();for (SearchHit hitsHit : hitsHits) {String sourceAsString = hitsHit.getSourceAsString();Account account = JSONObject.parseObject(sourceAsString, Account.class);System.out.println(account);}//4,提取聚合信息Aggregations aggregations = searchResponse.getAggregations();Terms ageAggRes = aggregations.get("ageAgg");List<? extends Terms.Bucket> aggResBuckets = ageAggRes.getBuckets();for (Terms.Bucket aggResBucket : aggResBuckets) {System.out.println("年齡:" + aggResBucket.getKeyAsString() + "總和:" + aggResBucket.getDocCount());}Avg balance = aggregations.get("avgBalance");System.out.println(balance.getValue());}/*** https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.4/java-rest-high-document-index.html*/@Testpublic void testEsAdd() throws IOException {//指定索引IndexRequest indexRequest = new IndexRequest("users");//指定idindexRequest.id("1");//封裝數(shù)據(jù)User user = new User();user.setUserName("張三");user.setAge(27);user.setGender("M");String jsonString = JSONObject.toJSONString(user);//指定數(shù)據(jù)類型為JSONindexRequest.source(jsonString, XContentType.JSON);//執(zhí)行同步操作IndexResponse index = client.index(indexRequest, ElasticsearchConfig.COMMON_OPTIONS);System.out.println(index);}@Dataclass User {private String userName;private String gender;private Integer age;}}
kibanaGET /users/_search
{"took" : 1,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 1,"relation" : "eq"},"max_score" : 1.0,"hits" : [{"_index" : "users","_type" : "_doc","_id" : "1","_score" : 1.0,"_source" : {"age" : 27,"gender" : "M","userName" : "張三"}}]}
}
http://www.risenshineclean.com/news/62532.html

相關(guān)文章:

  • app大全軟件網(wǎng)站免費(fèi)下載域名解析網(wǎng)站
  • 深圳建網(wǎng)站好的公司好用的視頻播放器app
  • 惠州外貿(mào)網(wǎng)站建設(shè)北京seo排名技術(shù)
  • 開發(fā)區(qū)招聘網(wǎng)最新招聘百度上海推廣優(yōu)化公司
  • 南充網(wǎng)站制作他達(dá)那非副作用太強(qiáng)了
  • 怎樣進(jìn)行網(wǎng)站開發(fā)網(wǎng)絡(luò)公司關(guān)鍵詞排名
  • 網(wǎng)站搜索引擎優(yōu)化的內(nèi)容谷歌chrome瀏覽器官方下載
  • 軟件外包多少錢seo培訓(xùn)班
  • 最專業(yè)的網(wǎng)站建設(shè)公司杭州哪家seo公司好
  • 網(wǎng)站的作用和意義百度地圖導(dǎo)航
  • 做網(wǎng)站如何分類產(chǎn)品網(wǎng)絡(luò)推廣免費(fèi)網(wǎng)站
  • 永泰城鄉(xiāng)建設(shè)網(wǎng)站網(wǎng)絡(luò)營銷專業(yè)是干什么的
  • 做腳本的網(wǎng)站新聞熱點(diǎn)最新事件
  • 服務(wù)器與網(wǎng)站百度排名工具
  • 義烏網(wǎng)站建設(shè)制作商品牌策劃方案ppt
  • 網(wǎng)站建設(shè)服務(wù)合同需要哪些資料seo搜索引擎營銷工具
  • led燈籠河網(wǎng)站建設(shè)搜索引擎優(yōu)化員簡歷
  • 萬維網(wǎng)申請網(wǎng)站域名搜狗站長工具平臺
  • vb6做網(wǎng)站西安今天剛剛發(fā)生的新聞
  • 網(wǎng)站加速cdn寧德市人社局
  • h5高端網(wǎng)站建設(shè)谷歌搜索引擎在線
  • 林芝網(wǎng)站建設(shè)手機(jī)優(yōu)化器
  • 新網(wǎng)站優(yōu)化怎么做關(guān)鍵詞搜索優(yōu)化
  • 網(wǎng)絡(luò)商城網(wǎng)站怎樣做關(guān)鍵詞優(yōu)化專業(yè)網(wǎng)店推廣
  • 做網(wǎng)站下載線下引流的八種推廣方式
  • 黃驊港天氣預(yù)報武漢seo關(guān)鍵字優(yōu)化
  • 大畫冊設(shè)計網(wǎng)站百度推廣首頁
  • 中國互聯(lián)網(wǎng)站建設(shè)中心移動網(wǎng)站如何優(yōu)化排名
  • 成華區(qū)建設(shè)局質(zhì)檢站網(wǎng)站百度鏈接地址
  • 大型門戶網(wǎng)站建設(shè)效果好嗎小說百度搜索風(fēng)云榜