本地搭建es镜像环境及谷歌插件可视化环境
https://blog.csdn.net/qq_60191219/article/details/125867721?spm=1001.2014.3001.5501
一:配置文件 --用于配置链接
elasticsearch:
host: 127.0.0.1
port: 9200
scheme: http
delayTime: 10
index:
event: event
people: people
place: place
二:es工具类 --为service提供方法
package com.spacesystech.config;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Getter
@Configuration
public class ElasticSearchConfig {
@Value("${elasticsearch.host}")
private String esHost;
@Value("${elasticsearch.port}")
private int esPort;
@Value("${elasticsearch.scheme}")
private String scheme;
@Value("${elasticsearch.index.event:event}")
private String eventIndex;
@Value("${elasticsearch.index.people:people}")
private String peopleIndex;
@Value("${elasticsearch.index.place:place}")
private String placeIndex;
private RestHighLevelClient client;
@PostConstruct
public void init(){
HttpHost[] httpHosts = Stream.of(StringUtils.split(esHost, ","))

本文介绍了如何在本地搭建Elasticsearch环境,并通过Java进行配合使用。详细讲述了配置文件的设置,Elasticsearch工具类和服务的创建,以及提供了数据列表和分页查询的方法。

8305

被折叠的 条评论
为什么被折叠?



