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

用 可以做网站软件吗网站制

用 可以做网站软件吗,网站制,wordpress 主机推荐,网站 易用性原则1⃣️环境准备 准备 Java 环境#xff1a;终端输入 java -version 命令来确认版本是否符合 Elasticsearch 要求下载并解压 Elasticsearch#xff1a;前往#xff08;https://www.elastic.co/downloads/elasticsearch#xff09;选择适合你的 Mac 系统的 Elasticsearch 版本…1⃣️环境准备 准备 Java 环境终端输入 java -version 命令来确认版本是否符合 Elasticsearch 要求下载并解压 Elasticsearch前往https://www.elastic.co/downloads/elasticsearch选择适合你的 Mac 系统的 Elasticsearch 版本进行下载设置 Elasticsearch 配置在 config 目录下找到并打开 elasticsearch.yml 配置文件。根据你的需求修改其中的一些设置比如监听的端口、集群名称等启动 Elasticsearch打开终端进入 Elasticsearch 解压目录执行以下命令启动 Elasticsearch ./bin/elasticsearch验证 Elasticsearch 是否正常运行打开浏览器访问 http://localhost:9200 地址如果能看到返回的 JSON 格式的信息说明 Elasticsearch 已经成功安装并运行。 使用步骤 配置依赖在项目的构建文件例如Maven的pom.xml中添加Elasticsearch相关的依赖。这通常包括Spring Data Elasticsearch和Elasticsearch的Java客户端依赖。配置Elasticsearch连接信息在Spring的配置文件中配置Elasticsearch连接的一些必要信息例如主机名、端口号等。这些信息将用于与Elasticsearch建立连接。创建Elasticsearch实体类在Java中创建实体类可以使用注解标注字段与Elasticsearch中的文档属性的映射关系。这些实体类通常使用JPA或Spring Data Elasticsearch提供的注解来简化与Elasticsearch的数据交互。编写Elasticsearch相关的数据访问接口使用Spring Data Elasticsearch提供的Repository接口定义与Elasticsearch进行数据交互的查询方法。可以通过方法命名规则或自定义查询语句实现各种查询操作。注入Elasticsearch的Repository在需要使用Elasticsearch的地方通过依赖注入方式获取到Elasticsearch的Repository。可以在Service层或Controller层中使用该Repository来进行查询、保存、更新等操作。执行Elasticsearch操作通过调用Elasticsearch的Repository方法执行对Elasticsearch的数据操作。可以执行各种查询例如基于关键字的全文搜索、聚合操作等。 2⃣️使用 要使用Elasticsearch进行增删改查等操作你可以通过Postman来实现。下面我将提供一个使用RESTful API来演示的示例 创建索引库 添加文档(添加行) 查询索引库 修改索引库 删除索引库 3⃣️与Java使用 如何使用Java与Elasticsearch进行索引的创建、文档的增加、查询、修改和删除操作 添加Elasticsearch Maven依赖 在pom.xml文件中添加以下依赖项 dependenciesdependencygroupIdorg.elasticsearch.client/groupIdartifactIdelasticsearch-rest-high-level-client/artifactIdversion7.13.3/version/dependencydependencygroupIdorg.elasticsearch.client/groupIdartifactIdelasticsearch-rest-client/artifactIdversion7.13.3/version/dependency /dependencies创建索引库 import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.indices.CreateIndexRequest; import org.elasticsearch.client.indices.CreateIndexResponse; import org.elasticsearch.client.RestClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent;// 创建RestHighLevelClient客户端 RestHighLevelClient client new RestHighLevelClient(RestClient.builder(localhost:9200));// 创建索引请求 CreateIndexRequest request new CreateIndexRequest(my_index); request.settings(Settings.builder().put(index.number_of_shards, 1).put(index.number_of_replicas, 0));// 创建映射 XContentBuilder mapping JsonXContent.contentBuilder().startObject().startObject(properties).startObject(user).field(type, keyword).endObject().startObject(postDate).field(type, date).endObject().startObject(message).field(type, text).endObject().endObject().endObject(); request.mapping(mapping);// 执行创建索引请求 CreateIndexResponse response client.indices().create(request, RequestOptions.DEFAULT); if (response.isAcknowledged()) {System.out.println(索引创建成功); } else {System.out.println(索引创建失败); }// 关闭客户端 client.close();添加文档 import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.client.RestClient;// 创建RestHighLevelClient客户端 RestHighLevelClient client new RestHighLevelClient(RestClient.builder(localhost:9200));// 构建索引请求 IndexRequest request new IndexRequest(my_index); request.id(1); String jsonString { \user\:\John\, \postDate\:\2023-09-25\, \message\:\This is a sample document\ }; request.source(jsonString, XContentType.JSON);// 执行索引请求 IndexResponse response client.index(request, RequestOptions.DEFAULT);// 获取响应结果 String index response.getIndex(); String id response.getId(); if (response.getResult() DocWriteResponse.Result.CREATED) {System.out.println(文档创建成功索引 index id id); } else if (response.getResult() DocWriteResponse.Result.UPDATED) {System.out.println(文档更新成功索引 index id id); }// 关闭客户端 client.close();查询索引库 import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.client.RestClient;// 创建RestHighLevelClient客户端 RestHighLevelClient client new RestHighLevelClient(RestClient.builder(localhost:9200));// 构建搜索请求 SearchRequest request new SearchRequest(my_index); SearchSourceBuilder searchSourceBuilder new SearchSourceBuilder(); searchSourceBuilder.query(QueryBuilders.matchQuery(message, sample)); request.source(searchSourceBuilder);// 执行搜索请求 SearchResponse response client.search(request, RequestOptions.DEFAULT);// 处理搜索结果 SearchHits hits response.getHits(); for (SearchHit hit : hits.getHits()) {String sourceAsString hit.getSourceAsString();System.out.println(sourceAsString); }// 关闭客户端 client.close();修改索引库 import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateResponse; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.client.RestClient;// 创建RestHighLevelClient客户端 RestHighLevelClient client new RestHighLevelClient(RestClient.builder(localhost:9200));// 构建更新请求 UpdateRequest request new UpdateRequest(my_index, 1).doc(XContentFactory.jsonBuilder().startObject().field(message, Updated document).endObject());// 执行更新请求 UpdateResponse response client.update(request, RequestOptions.DEFAULT); String index response.getIndex(); String id response.getId(); if (response.getResult() DocWriteResponse.Result.UPDATED) {System.out.println(文档更新成功索引 index id id); } else if (response.getResult() DocWriteResponse.Result.NOOP) {System.out.println(文档未发生更新索引 index id id); }// 关闭客户端 client.close();删除索引库 import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteResponse; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestClient;// 创建RestHighLevelClient客户端 RestHighLevelClient client new RestHighLevelClient(RestClient.builder(localhost:9200));// 构建删除请求 DeleteRequest request new DeleteRequest(my_index, 1);// 执行删除请求 DeleteResponse response client.delete(request, RequestOptions.DEFAULT); String index response.getIndex(); String id response.getId(); if (response.getResult() DocWriteResponse.Result.DELETED) {System.out.println(文档删除成功索引 index id id); } else if (response.getResult() DocWriteResponse.Result.NOT_FOUND) {System.out.println(文档未找到索引 index id id); }// 关闭客户端 client.close();
http://www.w-s-a.com/news/502806/

相关文章:

  • 建设网站网站首页购物网站开发代码
  • 淘宝客怎么建立网站网站360优化
  • 安徽建海建设工程有限公司网站网站空间和域名价格
  • 农产品网站建设策划哪里有做枪网站的
  • 更改各网站企业信息怎么做张家港企业网站制作
  • 郑州网站建设咨询银川做网站哪家好
  • 微信网站 微信支付合肥seo排名收费
  • 织梦做的网站如何上线广东省广州市番禺区南村镇
  • 网站设计的导航栏怎么做太原有网站工程公司吗
  • 苏州虎丘区建设局网站如何在一个数据库做两个网站
  • 淘宝天猫优惠券网站建设费用腾讯邮箱企业邮箱登录
  • 深圳福田做网站公司海航科技网站建设
  • 网站降权查询wordpress更换文章背景色
  • 大型电商网站开发金融企业网站建设公司
  • 成都营销型网站建设价格化妆品品牌推广方案
  • 深圳公司手机网站制作苏州网站推广哪家好
  • 网站建设开发方式包括购买学校网站建设费计入什么科目
  • 做简单网站的框架图中小微企业查询平台
  • 哪些网站可以免费做产品推广建设建设部网站
  • 网站开发销售怎么做django做网站
  • 淘宝客网站做百度竞价万网域名怎么绑定网站
  • 建设网站找哪个公司北京知名大公司有哪些
  • 专业彩票网站开发网站流量在哪设置
  • 网站建设对应的岗位榆林做网站公司
  • 网站建设公司怎么算专业js网站分页怎么做
  • 网和网站的区别phpcms和帝国cms哪个好
  • wordpress改网站名字长沙网络营销外包
  • 宝塔怎么做第二个网站网站内容设计遵循的原则有
  • 网站违反了 google 质量指南免费ppt模版网站
  • 郑州网站建设郑州网站建设成都那家网站建设好