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

steamcn网站是谁做的最新热搜新闻

steamcn网站是谁做的,最新热搜新闻,建设工程扣分查询网站,定制网站建设开发维护天行健,君子以自强不息;地势坤,君子以厚德载物。 每个人都有惰性,但不断学习是好好生活的根本,共勉! 文章均为学习整理笔记,分享记录为主,如有错误请指正,共同学习进步。…

天行健,君子以自强不息;地势坤,君子以厚德载物。


每个人都有惰性,但不断学习是好好生活的根本,共勉!


文章均为学习整理笔记,分享记录为主,如有错误请指正,共同学习进步。

文章目录

  • 一、服务安装参考
  • 二、Java实现新增数据到ES
    • 1. 环境
    • 2. 包结构
    • 3. 依赖引入
    • 4. http请求工具
    • 5. 测试代码
    • 6. 访问kibana服务


一、服务安装参考

首先需要准备好elasticsearch和kibana
elasticsearch的下载、安装、使用可参考:Elasticsearch安装
kibana的下载、安装、使用可参考:Kibana安装、配置
服务的启动使用和数据增删改查可参考:kibana操作elasticsearch(增删改查)
在进行一下Java实现之前,先将es服务和kibana服务启动

二、Java实现新增数据到ES

Elasticsearch的服务开启后,可以使用http请求进行调用接口来操作Elasticsearch数据
请求的url格式如下:

http://localhost:9200/index/type/id

对于Java来说,可以使用http请求工具进行实现,同时传参,参数为json类型数据
具体实现如下

1. 环境

并非要求,只是我这里使用的这个环境
JDK 1.8
Maven 3.9.4
IDEA 2023.2.1

2. 包结构

这里主要用到三个文件:pom引入依赖,HttpClientUtils是请求工具,EsHttpRequestController是请求调用测试
在这里插入图片描述

3. 依赖引入

引入http工具所需要的依赖,也就是实现请求的依赖
传入的参数为json类型所以也需要json工具的依赖
pom.xml完整内容

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.es</groupId><artifactId>ES-HTTP</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore --><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpcore</artifactId><version>4.4.14</version></dependency><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5.13</version></dependency><!--json工具--><dependency><groupId>com.alibaba.fastjson2</groupId><artifactId>fastjson2</artifactId><version>2.0.33</version></dependency></dependencies></project>

4. http请求工具

HttpClientUtils.java

package com.es.utils;import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;/*** @ClassDescription:* @JdkVersion: 1.8* @Author: 李白* @Created: 2023/10/16 16:12*/
public class HttpClientUtils {public static void post(){}public static String doPost(String url, String str, String encoding) {String body = "";try {// 创建httpclient对象CloseableHttpClient client = HttpClients.createDefault();// 创建post方式请求对象HttpPost httpPost = new HttpPost(url);// 设置参数到请求对象中httpPost.setEntity(new StringEntity(str, encoding));// 设置header信息// 指定报文头【Content-type】、【User-Agent】httpPost.setHeader("Content-type", "application/json;charset=UTF-8");// 执行请求操作,并拿到结果(同步阻塞)CloseableHttpResponse response = client.execute(httpPost);// 获取结果实体HttpEntity entity = response.getEntity();if (entity != null) {// 按指定编码转换结果实体为String类型body = EntityUtils.toString(entity, encoding);}EntityUtils.consume(entity);// 释放链接response.close();return body;} catch (Exception e1) {e1.printStackTrace();return "";}}}

5. 测试代码

编写mian方法执行请求存数据到es
EsHttoRequestController.java

package com.es.test;import com.alibaba.fastjson2.JSONObject;
import com.es.utils.HttpClientUtils;/*** @ClassDescription:* @JdkVersion: 1.8* @Author: 李白* @Created: 2023/10/16 16:12*/
public class EsHttpRequestController {public static void main(String[] args) {JSONObject js = new JSONObject();js.put("name","杜甫");js.put("age","6800");js.put("gender","男");String jsonStr = js.toJSONString();HttpClientUtils.doPost("http://127.0.0.1:9200/deviceinfo/users/1002",jsonStr,"UTF-8");}}

6. 访问kibana服务

先看kibana服务查看数据
打开侧边栏,Analytics–Discover
在这里插入图片描述
查看现有数据
在这里插入图片描述
执行5. 测试代码的代码,然后刷新界面查看新增数据
如下,新增成功
在这里插入图片描述


感谢阅读,祝君暴富!

http://www.hkea.cn/news/67548/

相关文章:

  • 网页与制作唐山seo推广公司
  • 自己做的网站怎么弄到网上在线网页制作
  • 电商网站 设计方案百度的排名规则详解
  • 福建省建设厅网站余外链链接平台
  • 广告营销网站市场推广方案
  • 徐州企业做网站软文是什么文章
  • 网站代码备份如何优化seo
  • 百度网站公司信息推广怎么做天津做网站的网络公司
  • wordpress在线pdfseo百度站长工具查询
  • 太仓网站建设有限公司网站设计公司怎么样
  • 网站去哪做在线crm软件
  • 做360手机网站快速汕头seo排名收费
  • 网站建设总做总结宜兴百度推广公司
  • 做毕业网站的周记外贸建站优化
  • 南昌市住房和城乡建设局网站百度官网推广平台电话
  • 真人做视频网站百度怎么发布广告
  • 网站页面优化包括怎么给网站做优化
  • 哪个网站用帝国cms做的软文素材网
  • 网站建设需要的资料深圳精准网络营销推广
  • 客户网站建设公司网站排名提升软件
  • 网站建设与维护试卷论文怎么在百度上做广告
  • 做博客网站要什么技术百度网站网址是多少
  • 河北建设厅官方网站八大员考试站长工具查询
  • 大连 做网站公司爱站工具包的主要功能
  • ps做简洁大气网站必应bing国内版
  • 做公司标志用哪个网站营销自动化
  • wordpress5.0.3厦门百度seo
  • 网站开发 企业 定制系统优化大师安卓版
  • 网站内链符号seo百度站长工具
  • 网站页面太多是否做静态seo优化软件