当前位置: 首页 > news >正文

手机网站微信登录接口用c语言做公司网站

手机网站微信登录接口,用c语言做公司网站,青岛航拍公司,大冶专业建站公司最近升级了Elasticsearch版本#xff0c;从7.X升级到8.X的变化还是比较大的#xff0c;原来7版本用的是RestHighLevelClient#xff0c;8.X弃用RestHighLevelClient转而支持ElasticsearchClient#xff0c;并且api调用方式经过建造者模式的改造#xff0c;变成了链式调用。…最近升级了Elasticsearch版本从7.X升级到8.X的变化还是比较大的原来7版本用的是RestHighLevelClient8.X弃用RestHighLevelClient转而支持ElasticsearchClient并且api调用方式经过建造者模式的改造变成了链式调用。 因此为了更好地使用ElasticsearchClient的api操作Elasticsearch封装了一个工具类包含了常用的一些数据操作的方法。废话不多说直接上代码。。。 1、pom依赖 dependencygroupIdco.elastic.clients/groupIdartifactIdelasticsearch-java/artifactIdversion8.15.2/version/dependencydependencyartifactIdelasticsearch-rest-client/artifactIdgroupIdorg.elasticsearch.client/groupIdversion8.15.2/version/dependencydependencygroupIdcom.alibaba/groupIdartifactIdfastjson/artifactIdversion2.0.30/version/dependency 2、工具类代码 import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch._types.Result; import co.elastic.clients.elasticsearch._types.SortOrder; import co.elastic.clients.elasticsearch._types.Time; import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery; import co.elastic.clients.elasticsearch.core.*; import co.elastic.clients.elasticsearch.core.bulk.BulkOperation; import co.elastic.clients.elasticsearch.indices.AnalyzeRequest; import co.elastic.clients.elasticsearch.indices.AnalyzeResponse; import co.elastic.clients.elasticsearch.indices.CreateIndexResponse; import co.elastic.clients.elasticsearch.indices.analyze.AnalyzeToken; import co.elastic.clients.json.jackson.JacksonJsonpMapper; import co.elastic.clients.transport.rest_client.RestClientTransport; import com.alibaba.fastjson.JSONObject; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClientBuilder; import java.io.IOException; import java.io.StringReader; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors;/*** Elasticsearch工具类* Elasticsearch版本8.15.3*/ public class ElasticsearchJavaClient {private ElasticsearchClient client;/*** 构造方法获取客户端未开启认证* param httpUrls*/public ElasticsearchJavaClient(String[] httpUrls){HttpHost[] httpHosts Arrays.stream(httpUrls).map(HttpHost::create).toArray(HttpHost[]::new);this.client new ElasticsearchClient(new RestClientTransport(RestClient.builder(httpHosts).build(),new JacksonJsonpMapper()));}/*** 构造方法获取客户端开启认证通过用户名密码进行认证并获取客户端* param httpUrls* param username* param password*/public ElasticsearchJavaClient(String[] httpUrls, String username, String password){HttpHost[] httpHosts Arrays.stream(httpUrls).map(HttpHost::create).toArray(HttpHost[]::new);final CredentialsProvider credentialsProvider new BasicCredentialsProvider();credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));RestClientBuilder builder RestClient.builder(httpHosts);builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {Overridepublic HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) {return httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);}});this.client new ElasticsearchClient(new RestClientTransport(builder.build(), new JacksonJsonpMapper()));}/*** 创建索引* param indexName 索引名* param numberOfShards 分片数* param numberOfReplicas 副本数* param mapping mapping设计json字符串* return*/public boolean createIndex(String indexName, Integer numberOfShards,Integer numberOfReplicas, String mapping) {CreateIndexResponse response null;try {response client.indices().create(builder - builder.index(indexName).settings(b - b.numberOfReplicas(numberOfReplicas.toString()).numberOfShards(numberOfShards.toString())).mappings(a - a.withJson(new StringReader(mapping))));} catch (IOException e) {e.printStackTrace();} finally {client.shutdown();}return response.acknowledged();}/*** 删除索引* param indexName 索引名* return*/public boolean deleteIndex(String indexName) {try {return client.indices().delete(a - a.index(indexName)).acknowledged();} catch (IOException e) {e.printStackTrace();} finally {client.shutdown();}return false;}/*** 判断索引是否已存在* param indexName 索引名* return*/public boolean indexExisit(String indexName) {try {return client.indices().exists(req - req.index(indexName)).value();} catch (IOException e) {e.printStackTrace();} finally {client.shutdown();}return false;}/*** 由于数据落盘有默认的1秒延迟刷新后使数据能被检索到* param indexString*/public void refresh(String indexString){try {client.indices().refresh(req - req.index(indexString));} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}}/*** 插入数据* param indexName* param data* return*/public String insertData(String indexName, JSONObject data){try {IndexResponse response client.index(a - a.index(indexName).document(data));return response.id();} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}return null;}/*** 根据索引和_id查询数据* param indexName* param id* return*/public MapString, Object getDocById(String indexName, String id) {GetRequest request GetRequest.of(g - g.index(indexName).id(id));try {GetResponseMap response client.get(request, Map.class);if(response.found()){return response.source();}} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}return null;}/*** 根据索引和_id查询数据* param indexName* param id* return*/public JSONObject getDocInfoById(String indexName, String id) {GetRequest request GetRequest.of(g - g.index(indexName).id(id));try {GetResponseJSONObject response client.get(request, JSONObject.class);if(response.found()){return response.source();}} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}return null;}/*** 根据索引和_id查询数据并过滤掉无需返回的字段* param indexName* param id* param excludes* return*/public JSONObject getDocInfoById(String indexName, String id, String [] excludes) {GetRequest request GetRequest.of(g - g.index(indexName).id(id).sourceExcludes(Arrays.asList(excludes)));try {GetResponseJSONObject response client.get(request, JSONObject.class);if(response.found()){return response.source();}} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}return null;}/*** 根据索引和_id查询数据并过指定要返回的字段* param indexName* param id* param includes* return*/public JSONObject getDocInfoByIdWithIncludes(String indexName, String id, String [] includes) {GetRequest request GetRequest.of(g - g.index(indexName).id(id).sourceIncludes(Arrays.asList(includes)));try {GetResponseJSONObject response client.get(request, JSONObject.class);if(response.found()){return response.source();}} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}return null;}/*** 判断数据是否存在* param indexName* param id* return*/public boolean exists(String indexName, String id) {GetRequest request GetRequest.of(g - g.index(indexName).id(id));try {GetResponseJSONObject response client.get(request, JSONObject.class);return response.found();} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}return false;}/*** 根据索引和_id删除数据* param indexName* param id* return*/public boolean deleteDocById(String indexName, String id) {DeleteRequest request DeleteRequest.of(a - a.index(indexName).id(id));try {DeleteResponse response client.delete(request);if(response ! null response.result() ! null){return Result.Deleted.jsonValue().equals(response.result().jsonValue());}} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}return false;}/*** 更新数据* param indexName* param id* param newDoc* return*/public boolean updateDocById(String indexName, String id, JSONObject newDoc) {UpdateRequest request UpdateRequest.of(r - r.id(id).index(indexName).doc(newDoc));request.refresh();try {UpdateResponse response client.update(request, JSONObject.class);if(response ! null response.result() ! null){return Result.Updated.jsonValue().equals(response.result().jsonValue());}} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}return false;}/*** 对输入的text使用analyzerName进行分词返回分词后的词项* param analyzerName* param text* return*/public ListAnalyzeToken analyze(String analyzerName, String text){AnalyzeRequest analyzeRequest new AnalyzeRequest.Builder().analyzer(analyzerName).text(text).build();AnalyzeResponse response null;try {response client.indices().analyze(analyzeRequest);} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}return response.tokens();}/*** 批量删除* param requestList* return*/public boolean bulkDelete(ListDeleteRequest requestList){ListBulkOperation ops requestList.stream().map(req - BulkOperation.of(op - op.delete(d - d.id(req.id()).index(req.index())))).collect(Collectors.toList());try {BulkResponse response client.bulk(r - r.operations(ops));if(response ! null ){return true;}} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}return false;}/*** 批量更新* param requestList* return*/public boolean bulkUpdate(ListUpdateRequest requestList){ListBulkOperation ops requestList.stream().map(req - BulkOperation.of(op - op.update(d - d.id(req.id()).index(req.index()).action(a - a.doc(req.doc()))))).collect(Collectors.toList());try {BulkResponse response client.bulk(r - r.operations(ops));if(response ! null ){return true;}} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}return false;}/*** 批量插入数据* param requestList* return*/public boolean bulkInsert(ListIndexRequest requestList){ListBulkOperation ops requestList.stream().map(req - BulkOperation.of(op - op.index(i - i.document(req.document()).index(req.index())))).collect(Collectors.toList());try {BulkResponse response client.bulk(r - r.operations(ops));if(response ! null ){return true;}} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}return false;}/*** 通过脚本批量更新* param index* param query* param script* return*/public boolean updateByquery(String index, BoolQuery query, String script){try {UpdateByQueryResponse response client.updateByQuery(q - q.index(index).query(query._toQuery()).script(s - s.source(script)));if(response ! null ){return true;}} catch (IOException e) {e.printStackTrace();}finally {client.shutdown();}return false;}/*** 检索* param indexName* param pageNo* param pageSize* param sortField* param sortOrder* param boolQuery* return*/public SearchResponse search(String indexName, Integer pageNo, Integer pageSize,String sortField, SortOrder sortOrder, BoolQuery boolQuery) {SearchRequest request new SearchRequest.Builder().index(indexName).query(q - q.bool(boolQuery)).from((pageNo - 1) * pageSize).size(pageSize).sort(s - s.field(f - f.field(sortField).order(sortOrder))).build();SearchResponse response null;try {response client.search(request, JSONObject.class);} catch (IOException e) {e.printStackTrace();}return response;}public SearchResponse search(String indexName, Integer pageNo, Integer pageSize,String sortField, SortOrder sortOrder, BoolQuery boolQuery, String[] excludes) {SearchRequest request new SearchRequest.Builder().index(indexName).query(q - q.bool(boolQuery)).source(a - a.filter(f - f.excludes(Arrays.asList(excludes)))).from((pageNo - 1) * pageSize).size(pageSize).sort(s - s.field(f - f.field(sortField).order(sortOrder))).build();SearchResponse response null;try {response client.search(request, JSONObject.class);} catch (IOException e) {e.printStackTrace();}return response;}public SearchResponse search(String indexName, Integer pageNo, Integer pageSize, BoolQuery boolQuery,String sortField, SortOrder sortOrder, String sortField2, SortOrder sortOrder2) {SearchRequest request new SearchRequest.Builder().index(indexName).query(q - q.bool(boolQuery)).from((pageNo - 1) * pageSize).size(pageSize).sort(s - s.field(f - f.field(sortField).order(sortOrder).field(sortField2).order(sortOrder2))).build();SearchResponse response null;try {response client.search(request, JSONObject.class);} catch (IOException e) {e.printStackTrace();}return response;}public SearchResponse search(String indexName, Integer pageNo, Integer pageSize, BoolQuery boolQuery,String sortField, SortOrder sortOrder, String sortField2, SortOrder sortOrder2,String[] excludes) {SearchRequest request new SearchRequest.Builder().index(indexName).query(q - q.bool(boolQuery)).source(a - a.filter(f - f.excludes(Arrays.asList(excludes)))).from((pageNo - 1) * pageSize).size(pageSize).sort(s - s.field(f - f.field(sortField).order(sortOrder).field(sortField2).order(sortOrder2))).build();SearchResponse response null;try {response client.search(request, JSONObject.class);} catch (IOException e) {e.printStackTrace();}return response;}public SearchResponse search(String indexName, Integer pageNo, Integer pageSize, BoolQuery boolQuery,String sortField, SortOrder sortOrder, String[] includes, String[] excludes) {SearchRequest request new SearchRequest.Builder().index(indexName).query(q - q.bool(boolQuery)).source(a - a.filter(f - f.excludes(Arrays.asList(excludes)).includes(Arrays.asList(includes)))).from((pageNo - 1) * pageSize).size(pageSize).sort(s - s.field(f - f.field(sortField).order(sortOrder))).build();SearchResponse response null;try {response client.search(request, JSONObject.class);} catch (IOException e) {e.printStackTrace();}return response;}public SearchResponse search(String indexName, Integer pageNo, Integer pageSize, BoolQuery boolQuery,String sortField, SortOrder sortOrder, String time) {SearchRequest request new SearchRequest.Builder().index(indexName).query(q - q.bool(boolQuery)).from((pageNo - 1) * pageSize).size(pageSize).scroll(new Time.Builder().time(time).build()).sort(s - s.field(f - f.field(sortField).order(sortOrder))).build();SearchResponse response null;try {response client.search(request, JSONObject.class);} catch (IOException e) {e.printStackTrace();}return response;}/*** 查询符合条件的数据条数* param indexName* param boolQuery* return*/public CountResponse count(String indexName, BoolQuery boolQuery) {try {return client.count(c - c.index(indexName).query(q - q.bool(boolQuery)));} catch (IOException e) {e.printStackTrace();}return null;}public SearchResponse search(String indexName, BoolQuery boolQuery) {SearchRequest request new SearchRequest.Builder().index(indexName).query(q - q.bool(boolQuery)).build();SearchResponse response null;try {response client.search(request, JSONObject.class);} catch (IOException e) {e.printStackTrace();}return response;}public SearchResponse search(String indexName, BoolQuery boolQuery, int size) {SearchRequest request new SearchRequest.Builder().index(indexName).query(q - q.bool(boolQuery)).size(size).build();SearchResponse response null;try {response client.search(request, JSONObject.class);} catch (IOException e) {e.printStackTrace();}return response;} }如果本文对你有帮助请点赞、收藏 关注谢谢本文将持续更新
http://www.dnsts.com.cn/news/61486.html

相关文章:

  • 深圳网站建设哪个公司好网站建设模板源码特效
  • 焊枪公司网站怎么做品牌网上做推广
  • 混沌鸿蒙网站建设温州集团网站建设公司
  • 触屏网站模板免费站推广网站2022
  • 开网站怎么开网站流量钱是谁给的
  • 做网站和做微商城有什么区别查询网站怎么做的
  • 网站片头怎么做企业官方网站是什么
  • 个人阿里云账号可以做网站备案电子商务网站运营
  • 建国外网站需要多少钱怎么打开手机app
  • 建筑专业网站泰安那家网好
  • mvc6 网站开发实战推广过程
  • 网站开发到上线的流程福田做商城网站建设哪家公司便宜点
  • 马家堡网站建设大型h5手游平台
  • 中国新农村建设促进会网站顺德网站建设收费标准
  • 贵州省安顺市网站建设网站访客
  • 微信 网站 织梦自己做网站做外贸可以吗
  • 山东食品行业网站模板百度广告联盟电话
  • 延庆网站建设天津专业网站制作设计
  • 哪个网站做图找图片网站做视频在线观看网址
  • 网址收录网站可信赖的购物网站建设
  • 西安网站建设缑阳建但是网站相关内容和程序并没有建设完_其次网站公司给我公司的
  • 怎么做网站前台龙岗微信网站制作
  • 珠海网站制作渠道娄底营销型网站建设
  • 江苏省建设工程地方标准网站东莞快速做网站
  • 山东网站建设开发维护wordpress更改固定连接404
  • 网站建设优化方法网络网站是多少钱
  • 电子商务营销案例分析镇江网站建设优化
  • 常州网站建设联系电话个人网站多少钱一年
  • 做网站怎样上传文件网站搭建免费
  • 做网站的参考文献清溪网站建设公司