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

网站开发实战答案网站建设是什么语言

网站开发实战答案,网站建设是什么语言,商城系统平台开发,做金属的网站Es的java API客户端 在Es7.15版本之后#xff0c;es官方将它的高级客户端RestHighLevelClient标记为弃用状态。同时推出了全新的java API客户端Elasticsearch Java API Client#xff0c;该客户端也将在Elasticsearch8.0及以后版本中成为官方推荐使用的客户端。 Elasticsea…Es的java API客户端 在Es7.15版本之后es官方将它的高级客户端RestHighLevelClient标记为弃用状态。同时推出了全新的java API客户端Elasticsearch Java API Client该客户端也将在Elasticsearch8.0及以后版本中成为官方推荐使用的客户端。 Elasticsearch Java API Client支持除Vector title search API和Find structure API之外的所有Elasticsearch API。且支持所有API数据类型并且不再有原始JSON Value属性。它是针对Elasticsearch8.0及之后版本的客户端。 maven中引入依赖坐标 dependencygroupIdorg.elasticsearch.client/groupIdartifactIdelasticsearch-rest-client/artifactIdversion8.12.2/version/dependencydependencygroupIdco.elastic.clients/groupIdartifactIdelasticsearch-java/artifactIdversion8.12.2/versionexclusionsexclusiongroupIdorg.elasticsearch.client/groupIdartifactIdelasticsearch-rest-client/artifactId/exclusion/exclusions/dependency创建连接 Beanpublic ElasticsearchClient elasticsearchClient(Value(${elasticsearch.xxxx}) String serverUrl,Value(${elasticsearch.xxxxx}) String apiKey) {RestClient restClient RestClient.builder(HttpHost.create(serverUrl)).setDefaultHeaders(new Header[]{new BasicHeader(Authorization, ApiKey apiKey),}).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());return new ElasticsearchClient(transport);}索引index Testpublic void create() throws IOException {// 创建低级客户端RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();// 使用Jackson映射器创建传输层ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());// 创建API客户端ElasticsearchClient client new ElasticsearchClient(transport);// 创建索引CreateIndexResponse createIndexResponse client.indices().create(c - c.index(user_test));// 响应状态Boolean acknowledged createIndexResponse.acknowledged();System.out.println(索引操作 acknowledged);// 关闭ES客户端transport.close();restClient.close();}查询索引 Testpublic void query() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost,9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 查询索引GetIndexResponse getIndexResponse client.indices().get(e - e.index(user_test));System.out.println(getIndexResponse.result() getIndexResponse.result());System.out.println(getIndexResponse.result().keySet() getIndexResponse.result().keySet());transport.close();restClient.close();} 如果查询的index不存在会在控制台抛出index_not_found_exception 删除索引 Testpublic void delete() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 删除索引DeleteIndexResponse deleteIndexResponse client.indices().delete(e - e.index(user_test));System.out.println(删除操作 deleteIndexResponse.acknowledged());transport.close();restClient.close();}文档document的操作 添加document Testpublic void addDocument() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 向user对象中添加数据User user new User(java客户端, 男, 18);// 向索引中添加数据CreateResponse createResponse client.create(e - e.index(user_test).id(1001).document(user));System.out.println(createResponse.result() createResponse.result());transport.close();restClient.close();}注index中参数为文档所属的索引名id中参数为当文档的iddocument为文档数据新版本支持直接传入java对象。 查询document Testpublic void queryDocument() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 构建请求GetResponseUser getResponse client.get(e - e.index(user_test).id(1001), User.class);System.out.println(getResponse.source().toString() getResponse.source().toString());transport.close();restClient.close();}注如果查不到控制台抛出NullPointerException 修改document Testpublic void modifyDocument() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 使用map集合封装需要修改的内容MapString, Object map new HashMap();map.put(name, java客户端aaa);// 构建请求UpdateResponseUser updateResponse client.update(e - e.index(user_test).id(1001).doc(map), User.class);System.out.println(updateResponse.result() updateResponse.result());transport.close();restClient.close();}删除document Testpublic void removeDocument() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 构建请求DeleteResponse deleteResponse client.delete(e - e.index(user_test).id(1001));System.out.println(deleteResponse.result() deleteResponse.result());transport.close();restClient.close();}批量添加document Testpublic void batchAddDocument() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 构建一个批量数据集合ListBulkOperation list new ArrayList();list.add(new BulkOperation.Builder().create(d - d.document(new User(test2, 男, 19)).id(1002).index(user_test)).build());list.add(new BulkOperation.Builder().create(d - d.document(new User(test3, 男, 20)).id(1003).index(user_test)).build());list.add(new BulkOperation.Builder().create(d - d.document(new User(test4, 女, 21)).id(1004).index(user_test)).build());// 调用bulk方法执行批量插入操作BulkResponse bulkResponse client.bulk(e - e.index(user_test).operations(list));System.out.println(bulkResponse.items() bulkResponse.items());transport.close();restClient.close();}批量添加的核心是需要构建一个泛型为BulkOperation的ArrayList集合实质上是将多个请求包装到一个集合中进行统一请求进行构建请求时调用bulk方法实现批量添加效果。 批量删除 Testpublic void batchDeleteDocument() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 构建一个批量数据集合ListBulkOperation list new ArrayList();list.add(new BulkOperation.Builder().delete(d - d.id(1002).index(user_test)).build());list.add(new BulkOperation.Builder().delete(d - d.id(1003).index(user_test)).build());// 调用bulk方法执行批量插入操作BulkResponse bulkResponse client.bulk(e - e.index(user_test).operations(list));System.out.println(bulkResponse.items() bulkResponse.items());transport.close();restClient.close();}全量查询 Testpublic void queryAllDocument() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 全量查询SearchResponseUser searchResponse client.search(e - e.index(user_test).query(q - q.matchAll(m - m)), User.class);HitsMetadataUser hits searchResponse.hits();for (HitUser hit : hits.hits()) {System.out.println(user hit.source().toString());}System.out.println(searchResponse.hits().total().value() searchResponse.hits().total().value());transport.close();restClient.close();}分页查询 Testpublic void pagingQueryDocument() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 分页查询SearchResponseUser searchResponse client.search(s - s.index(user_test).query(q - q.matchAll(m - m)).from(2).size(2), User.class);searchResponse.hits().hits().forEach(h - System.out.println(h.source().toString()));transport.close();restClient.close();}分页查询就是在全量查询的基础上增加了从第几条开始每页显示几条 排序查询 Testpublic void sortQueryDocument() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 排序查询SearchResponseUser searchResponse client.search(s - s.index(user_test).query(q - q.matchAll(m - m)).sort(o - o.field(f - f.field(age).order(SortOrder.Asc))), User.class);searchResponse.hits().hits().forEach(h - System.out.println(h.source().toString()));transport.close();restClient.close();}条件查询 Testpublic void conditionQueryDocument() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 条件查询SearchResponseUser searchResponse client.search(s - s.index(user_test).query(q - q.matchAll(m - m)).sort(o - o.field(f - f.field(age).order(SortOrder.Asc))).source(r - r.filter(f - f.includes(name, age).excludes())), User.class);searchResponse.hits().hits().forEach(h - System.out.println(h.source().toString()));transport.close();restClient.close();}includes是显示的字段excludes是排除的字段 组合查询 Testpublic void combinationQueryDocument() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 组合查询SearchResponseUser searchResponse client.search(s - s.index(user_test).query(q - q.bool(b - b.must(m - m.match(u - u.field(age).query(21))).must(m - m.match(u - u.field(sex).query(男))).mustNot(m - m.match(u - u.field(sex).query(女))))), User.class);searchResponse.hits().hits().forEach(h - System.out.println(h.source().toString()));transport.close();restClient.close();}Testpublic void combinationQueryDocument2() throws IOException {RestClient restClient RestClient.builder(new HttpHost(localhost, 9200)).build();ElasticsearchTransport transport new RestClientTransport(restClient, new JacksonJsonpMapper());ElasticsearchClient client new ElasticsearchClient(transport);// 组合查询SearchResponseUser searchResponse client.search(s - s.index(user_test).query(q - q.bool(b - b.should(h - h.match(u - u.field(age).query(19))).should(h - h.match(u - u.field(sex).query(男))))), User.class);searchResponse.hits().hits().forEach(h - System.out.println(h.source().toString()));transport.close();restClient.close();}
http://www.zqtcl.cn/news/996042/

相关文章:

  • 简单网站vs2008不能新建网站
  • 牌具做网站可以吗海外广告投放公司
  • 响应式单页网站模板宁波企业自助建站
  • 网站广告收费标准装饰设计公司起名
  • 网站开发人员构成中国兰州网官网
  • 网站设计的提案旅游网站建设风格
  • 成都网站建设的公司做高大上分析的网站
  • 专业企业网站建设公司成都的网站
  • 广东省建设教育协会官方网站首页怎么设置wordpress头像
  • 图书网站建设论文页游中心
  • 建网站的流程及注意事项任务网站建设
  • 河北邯郸做网站的公司哪家好辽源市住房和城乡建设局网站
  • 网站系统建设技术服务费安康市网站建设
  • 网络运行管理系统seo关键词优化方法
  • 西安学校网站建设价格徐州网页关键词优化
  • 上海哪个网站能应聘做家教的营销网站中最重要的部分是
  • 一个设计网站多少钱WordPress的简约博客主题
  • 普通的宣传网站用什么做济南市工程建设技术监督局网站
  • 合肥网站建设公司还有不dw如何制作表格网页
  • 讯美智能网站建设自己域名做网站
  • 自己做网站优化韩国外贸平台
  • 齐河建设局网站长沙市住房和建设局官方网站
  • 萧山区住房和城乡建设局网站wordpress网站合并
  • 做背景网站网站建设与维护制作网页
  • 网站建设公司知名营销型企业网站项目策划表
  • 写作网站哪个最好企业培训机构有哪些
  • 江苏省水利工程建设局网站域名不备案可以正常使用吗
  • 对网站开发语言的统计网站内容建设包括什么
  • 西安高端网站建设怎样开公司
  • 华为做网站免费签名设计在线生成