SpringBoot整合ElasticSearch

SpringBoot整合ElasticSearch

  • 配置
    • springboot版本
    • 目录结构
    • pom.xml
    • application.yml
  • 代码
    • ElasticSearchConfig.java
    • ElasticSearchController.java

配置

springboot版本

<parent>
   <groupId>org.springframework.bootgroupId>
   <artifactId>spring-boot-starter-parentartifactId>
   <version>2.3.12.RELEASEversion>
   <relativePath/> 
parent>

目录结构

SpringBoot整合ElasticSearch_第1张图片

pom.xml

<dependencies>
   ...
   <dependency>
      <groupId>org.apache.commonsgroupId>
      <artifactId>commons-lang3artifactId>
      <version>3.6version>
   dependency>
   <dependency>
      <groupId>com.alibabagroupId>
      <artifactId>fastjsonartifactId>
      <version>1.2.41version>
   dependency>
   <dependency>
      <groupId>org.elasticsearch.clientgroupId>
      <artifactId>elasticsearch-rest-high-level-clientartifactId>
   dependency>
   <dependency>
      <groupId>org.elasticsearch.clientgroupId>
      <artifactId>elasticsearch-rest-clientartifactId>
   dependency>
   <dependency>
      <groupId>org.elasticsearchgroupId>
      <artifactId>elasticsearchartifactId>
   dependency>
dependencies>

application.yml

#elasticsearch配置
elasticsearch:
  rest:
    #es节点地址,集群则用逗号隔开
    uris: 192.168.100.102:9200

代码

ElasticSearchConfig.java

package com.seven.config;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.*;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch<

你可能感兴趣的:(Springboot框架搭建,spring,boot,elasticsearch,jenkins,后端,spring,架构)