1、新增检索服务

2、优化pom文件
pull/254/head
xjs 4 years ago
parent 7f84c9964f
commit 771c524ae6

@ -107,6 +107,7 @@
<version>${bean-searcher.version}</version> <version>${bean-searcher.version}</version>
</dependency> </dependency>
<!--elasticsearch客户端-->
<dependency> <dependency>
<groupId>org.elasticsearch.client</groupId> <groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId> <artifactId>elasticsearch-rest-high-level-client</artifactId>

@ -44,7 +44,7 @@
<div v-loading="loading"> <div v-loading="loading">
<el-timeline v-for="(index,article) in articleList"> <el-timeline v-for="(article,index) in articleList">
<el-timeline-item :timestamp=article.createTime placement="top"> <el-timeline-item :timestamp=article.createTime placement="top">
<el-button type="text" <el-button type="text"

@ -0,0 +1,27 @@
package com.xjs.mall.search;
import com.ruoyi.common.security.annotation.EnableCustomConfig;
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
/**
* Search
* @author xiejs
* @since 2022-03-25
*/
@SpringBootApplication
@EnableCustomConfig
@EnableCustomSwagger2
@EnableRyFeignClients
public class MallSearchApp {
public static void main(String[] args) {
ConfigurableApplicationContext run = SpringApplication.run(MallSearchApp.class, args);
//String[] beanDefinitionNames = run.getBeanDefinitionNames();
//for (String beanDefinitionName : beanDefinitionNames) {
// System.out.println("beanDefinitionName:"+beanDefinitionName);
//}
}
}

@ -0,0 +1,58 @@
package com.xjs.mall.search.config;
import lombok.Data;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Elasticsearcn
*
* @author xiejs
* @since 2022-03-25
*/
@Configuration
@ConfigurationProperties(prefix = "elasticsearch")
@Data
public class ElasticsearchConfig {
/**
* esip
*/
private String ip;
/**
*
*/
private Integer port;
/**
*
*/
private String scheme;
public static final RequestOptions COMMON_OPTIONS;
static {
RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
//配置项.......
COMMON_OPTIONS = builder.build();
}
@Bean
public RestHighLevelClient restHighLevelClient() {
RestClientBuilder builder = RestClient.builder(new HttpHost(ip, port, scheme));
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);
return restHighLevelClient;
}
}

@ -0,0 +1,44 @@
package com.xjs.mall.search.controller;
import com.xjs.mall.other.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import static com.xjs.mall.search.config.ElasticsearchConfig.COMMON_OPTIONS;
/**
* @author xiejs
* @since 2022-03-26
*/
@RequestMapping("test")
@Api(tags = "test")
@RestController
public class TestController {
@Autowired
private RestHighLevelClient restHighLevelClient;
@GetMapping
@ApiOperation("测试")
public R test() throws IOException {
IndexRequest indexRequest = new IndexRequest("users");
indexRequest.id("1");
indexRequest.source("userName", "zs", "age", 18);
IndexResponse index = restHighLevelClient.index(indexRequest, COMMON_OPTIONS);
System.out.println(index.toString());
return R.ok();
}
}

@ -1,6 +1,6 @@
# Tomcat # Tomcat
server: server:
port: 9980 port: 9986
# Spring # Spring
spring: spring:

@ -0,0 +1,40 @@
package com.xjs.mall.search;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RestHighLevelClient;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import java.io.IOException;
import static com.xjs.mall.search.config.ElasticsearchConfig.COMMON_OPTIONS;
/**
* @author xiejs
* @since 2022-03-25
*/
@SpringBootTest(classes = MallSearchApp.class)
class ElasticsearchConfigTest {
@Resource
private RestHighLevelClient restHighLevelClient;
@Test
/**
* es
*/
public void indexData() throws IOException {
IndexRequest indexRequest = new IndexRequest("users");
indexRequest.id("1");
indexRequest.source("userName", "zs", "age", 18);
IndexResponse index = restHighLevelClient.index(indexRequest, COMMON_OPTIONS);
System.out.println(index.toString());
}
}

@ -0,0 +1,29 @@
# Tomcat
server:
port: 9980
# Spring
spring:
application:
# 应用名称
name: xjs-mall-ware
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 127.0.0.1:8848
config:
# 配置中心地址
server-addr: 127.0.0.1:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
#配置组
group: xjs
#命名空间
namespace: xjs-666
Loading…
Cancel
Save