pom-清理es依赖
This commit is contained in:
@@ -61,13 +61,3 @@ rocketmq:
|
||||
producer:
|
||||
group: peko-group
|
||||
sendMessageTimeout: 300000
|
||||
|
||||
## ES配置
|
||||
elasticsearch:
|
||||
clusterName: elasticsearch
|
||||
hostName: es-cn-2r42lphv9000nvr61.public.elasticsearch.aliyuncs.com
|
||||
port: 9200
|
||||
username: elastic
|
||||
password: xuanyin@es123
|
||||
roomIndex: yinyou_dev_room
|
||||
userIndex: yinyou_dev_users_202204121516
|
||||
|
@@ -3,9 +3,9 @@ spring:
|
||||
dynamic-datasource:
|
||||
master:
|
||||
poolName: master
|
||||
jdbcUrl: jdbc:mysql://124.156.164.187:3306/peko?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false&useSSL=false&useCursorFetch=true
|
||||
jdbcUrl: jdbc:mysql://129.226.62.202:3306/eparty?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false&useSSL=false&useCursorFetch=true
|
||||
username: root
|
||||
password: anan@dev##
|
||||
password: eparty@dev##
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
hikari:
|
||||
@@ -15,9 +15,9 @@ spring:
|
||||
max-lifetime: 7000
|
||||
slave:
|
||||
poolName: slave
|
||||
jdbcUrl: jdbc:mysql://124.156.164.187:3306/peko?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false&useSSL=false&useCursorFetch=true
|
||||
jdbcUrl: jdbc:mysql://129.226.62.202:3306/eparty?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false&useSSL=false&useCursorFetch=true
|
||||
username: root
|
||||
password: anan@dev##
|
||||
password: eparty@dev##
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
hikari:
|
||||
@@ -26,20 +26,20 @@ spring:
|
||||
connection-test-query: select 1
|
||||
max-lifetime: 7000
|
||||
redis:
|
||||
host: 124.156.164.187
|
||||
host: 129.226.62.202
|
||||
port: 6200
|
||||
maxTotal: 100
|
||||
maxIdle: 50
|
||||
maxWait: 2500
|
||||
testOnBorrow: true
|
||||
testOnReturn: true
|
||||
password: anan@dev@redis@#!
|
||||
password: pc8DphhaXwTe2jyv
|
||||
redisson:
|
||||
# file: classpath:redisson.yaml
|
||||
config: |
|
||||
singleServerConfig:
|
||||
address: redis://124.156.164.187:6200
|
||||
password: anan@dev@redis@#!
|
||||
address: redis://129.226.62.202:6200
|
||||
password: pc8DphhaXwTe2jyv
|
||||
connectionMinimumIdleSize: 4
|
||||
timeout: 10000
|
||||
threads: 8
|
||||
@@ -47,27 +47,9 @@ spring:
|
||||
codec: !<org.redisson.codec.JsonJacksonCodec> {}
|
||||
transportMode: "NIO"
|
||||
|
||||
##activemq 配置
|
||||
activemq:
|
||||
brokerUrl: tcp://124.156.164.187:61619
|
||||
user: system
|
||||
password: manager
|
||||
maxConnections: 50
|
||||
idleTimeout: 30000
|
||||
|
||||
## rocketmq 配置
|
||||
rocketmq:
|
||||
name-server: 124.156.164.187:9876
|
||||
name-server: 129.226.62.202:9876
|
||||
producer:
|
||||
group: peko-group
|
||||
sendMessageTimeout: 300000
|
||||
|
||||
## ES配置
|
||||
elasticsearch:
|
||||
clusterName: elasticsearch
|
||||
hostName: es-cn-2r42lphv9000nvr61.public.elasticsearch.aliyuncs.com
|
||||
port: 9200
|
||||
username: elastic
|
||||
password: xuanyin@es123
|
||||
roomIndex: yinyou_dev_room
|
||||
userIndex: yinyou_dev_users_202204121516
|
||||
group: eparty-group
|
||||
sendMessageTimeout: 300000
|
@@ -2166,26 +2166,6 @@ public class Constant {
|
||||
public static Integer apple_account = 5; //苹果账户
|
||||
}
|
||||
|
||||
/**
|
||||
* elasticsearch index 常量
|
||||
*/
|
||||
public static class ElasticsearchIndex {
|
||||
// 用户信息索引
|
||||
public static final String USER_INDEX = "accompany_user";
|
||||
//房间信息索引
|
||||
public static final String ROOM_INDEX = "accompany_room";
|
||||
}
|
||||
|
||||
/**
|
||||
* elasticsearch type 常量
|
||||
*/
|
||||
public static class ElasticsearchType {
|
||||
public static final String MV = "mv";
|
||||
public static final String MUSIC = "music";
|
||||
public static final String USER = "user";
|
||||
public static final String ROOM = "room";
|
||||
}
|
||||
|
||||
//钥匙记录类型
|
||||
public static class PrizeKeyRecordType {
|
||||
//购买钥匙
|
||||
|
@@ -1,27 +0,0 @@
|
||||
package com.accompany.business.elasticsearch;
|
||||
|
||||
/**
|
||||
* elasticsearch批量动作类型
|
||||
* @author xiaoyuyou
|
||||
* @date 2018/9/6 16:18
|
||||
*/
|
||||
public interface ElasticsearchBulkAction {
|
||||
|
||||
/**
|
||||
* 如果文档不存在,那么就创建它
|
||||
*/
|
||||
String CREATE = "create";
|
||||
/**
|
||||
* 创建一个新文档或者替换一个现有的文档
|
||||
*/
|
||||
String INDEX = "index";
|
||||
/**
|
||||
* 部分更新一个文档
|
||||
*/
|
||||
String UPDATE = "update";
|
||||
/**
|
||||
* 删除一个文档
|
||||
*/
|
||||
String DELETE = "delete";
|
||||
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
package com.accompany.business.elasticsearch;
|
||||
|
||||
/**
|
||||
* elasticsearch请求方法类型
|
||||
* @author xiaoyuyou
|
||||
* @date 2018/9/6 16:18
|
||||
*/
|
||||
public interface ElasticsearchRequestMethod {
|
||||
|
||||
/**
|
||||
* PUT请求
|
||||
*/
|
||||
String PUT = "PUT";
|
||||
/**
|
||||
* POST请求
|
||||
*/
|
||||
String POST = "POST";
|
||||
/**
|
||||
* GET请求
|
||||
*/
|
||||
String GET = "GET";
|
||||
/**
|
||||
* DELETE请求
|
||||
*/
|
||||
String DELETE = "DELETE";
|
||||
|
||||
}
|
@@ -1,169 +0,0 @@
|
||||
package com.accompany.business.elasticsearch;
|
||||
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 描述:
|
||||
*
|
||||
* @author yanpenglei
|
||||
* @create 2017-11-06 12:56
|
||||
**/
|
||||
public class EsPage {
|
||||
|
||||
// 指定的或是页面参数
|
||||
private int currentPage; // 当前页
|
||||
private int pageSize; // 每页显示多少条
|
||||
|
||||
// 查询es结果
|
||||
private int recordCount; // 总记录数
|
||||
private List<Map<String, Object>> recordList; // 本页的数据列表
|
||||
|
||||
private SearchHit[] searchHits;// 搜索结果
|
||||
|
||||
// 计算
|
||||
private int pageCount; // 总页数
|
||||
private int beginPageIndex; // 页码列表的开始索引(包含)
|
||||
private int endPageIndex; // 页码列表的结束索引(包含)
|
||||
|
||||
/**
|
||||
* 只接受前4个必要的属性,会自动的计算出其他3个属性的值
|
||||
*
|
||||
* @param currentPage
|
||||
* @param pageSize
|
||||
* @param recordCount
|
||||
* @param recordList
|
||||
*/
|
||||
public EsPage(int currentPage, int pageSize, int recordCount, List<Map<String, Object>> recordList) {
|
||||
this.currentPage = currentPage;
|
||||
this.pageSize = pageSize;
|
||||
this.recordCount = recordCount;
|
||||
this.recordList = recordList;
|
||||
|
||||
// 计算总页码
|
||||
pageCount = (recordCount + pageSize - 1) / pageSize;
|
||||
|
||||
// 计算 beginPageIndex 和 endPageIndex
|
||||
// >> 总页数不多于10页,则全部显示
|
||||
if (pageCount <= 10) {
|
||||
beginPageIndex = 1;
|
||||
endPageIndex = pageCount;
|
||||
}
|
||||
// >> 总页数多于10页,则显示当前页附近的共10个页码
|
||||
else {
|
||||
// 当前页附近的共10个页码(前4个 + 当前页 + 后5个)
|
||||
beginPageIndex = currentPage - 4;
|
||||
endPageIndex = currentPage + 5;
|
||||
// 当前面的页码不足4个时,则显示前10个页码
|
||||
if (beginPageIndex < 1) {
|
||||
beginPageIndex = 1;
|
||||
endPageIndex = 10;
|
||||
}
|
||||
// 当后面的页码不足5个时,则显示后10个页码
|
||||
if (endPageIndex > pageCount) {
|
||||
endPageIndex = pageCount;
|
||||
beginPageIndex = pageCount - 10 + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public EsPage(int currentPage, int pageSize, int recordCount, SearchHit[] searchHits) {
|
||||
this.currentPage = currentPage;
|
||||
this.pageSize = pageSize;
|
||||
this.recordCount = recordCount;
|
||||
this.searchHits = searchHits;
|
||||
|
||||
// 计算总页码
|
||||
pageCount = (recordCount + pageSize - 1) / pageSize;
|
||||
|
||||
// 计算 beginPageIndex 和 endPageIndex
|
||||
// >> 总页数不多于10页,则全部显示
|
||||
if (pageCount <= 10) {
|
||||
beginPageIndex = 1;
|
||||
endPageIndex = pageCount;
|
||||
}
|
||||
// >> 总页数多于10页,则显示当前页附近的共10个页码
|
||||
else {
|
||||
// 当前页附近的共10个页码(前4个 + 当前页 + 后5个)
|
||||
beginPageIndex = currentPage - 4;
|
||||
endPageIndex = currentPage + 5;
|
||||
// 当前面的页码不足4个时,则显示前10个页码
|
||||
if (beginPageIndex < 1) {
|
||||
beginPageIndex = 1;
|
||||
endPageIndex = 10;
|
||||
}
|
||||
// 当后面的页码不足5个时,则显示后10个页码
|
||||
if (endPageIndex > pageCount) {
|
||||
endPageIndex = pageCount;
|
||||
beginPageIndex = pageCount - 10 + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
public void setCurrentPage(int currentPage) {
|
||||
this.currentPage = currentPage;
|
||||
}
|
||||
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(int pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public int getRecordCount() {
|
||||
return recordCount;
|
||||
}
|
||||
|
||||
public void setRecordCount(int recordCount) {
|
||||
this.recordCount = recordCount;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getRecordList() {
|
||||
return recordList;
|
||||
}
|
||||
|
||||
public void setRecordList(List<Map<String, Object>> recordList) {
|
||||
this.recordList = recordList;
|
||||
}
|
||||
|
||||
public int getPageCount() {
|
||||
return pageCount;
|
||||
}
|
||||
|
||||
public void setPageCount(int pageCount) {
|
||||
this.pageCount = pageCount;
|
||||
}
|
||||
|
||||
public int getBeginPageIndex() {
|
||||
return beginPageIndex;
|
||||
}
|
||||
|
||||
public void setBeginPageIndex(int beginPageIndex) {
|
||||
this.beginPageIndex = beginPageIndex;
|
||||
}
|
||||
|
||||
public int getEndPageIndex() {
|
||||
return endPageIndex;
|
||||
}
|
||||
|
||||
public void setEndPageIndex(int endPageIndex) {
|
||||
this.endPageIndex = endPageIndex;
|
||||
}
|
||||
|
||||
public SearchHit[] getSearchHits() {
|
||||
return searchHits;
|
||||
}
|
||||
|
||||
public void setSearchHits(SearchHit[] searchHits) {
|
||||
this.searchHits = searchHits;
|
||||
}
|
||||
}
|
@@ -1,124 +0,0 @@
|
||||
package com.accompany.business.config;
|
||||
|
||||
import com.accompany.business.elasticsearch.ElasticsearchClientV2;
|
||||
import com.accompany.business.elasticsearch.ElasticsearchRestClient;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
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;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "elasticsearch")
|
||||
public class ElasticsearchConfig {
|
||||
|
||||
private String clusterName;
|
||||
private String hostName;
|
||||
private String username;
|
||||
private String password;
|
||||
private int port;
|
||||
|
||||
private String roomIndex;
|
||||
private String userIndex;
|
||||
|
||||
public String getClusterName() {
|
||||
return clusterName;
|
||||
}
|
||||
|
||||
public void setClusterName(String clusterName) {
|
||||
this.clusterName = clusterName;
|
||||
}
|
||||
|
||||
public String getHostName() {
|
||||
return hostName;
|
||||
}
|
||||
|
||||
public void setHostName(String hostName) {
|
||||
this.hostName = hostName;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RestClient restClient(){
|
||||
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) {
|
||||
credentialsProvider.setCredentials(AuthScope.ANY,
|
||||
new UsernamePasswordCredentials(username, password));
|
||||
}
|
||||
return RestClient.builder(new HttpHost(hostName, port))
|
||||
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RestHighLevelClient restHighLevelClient(){
|
||||
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) {
|
||||
credentialsProvider.setCredentials(AuthScope.ANY,
|
||||
new UsernamePasswordCredentials(username, password));
|
||||
}
|
||||
RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(hostName, port))
|
||||
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
|
||||
return new RestHighLevelClient(restClientBuilder);
|
||||
}
|
||||
|
||||
@Primary
|
||||
@Bean("elasticsearchRestClient")
|
||||
@DependsOn("restClient")
|
||||
public ElasticsearchRestClient elasticsearchRestClient(ElasticsearchConfig elasticsearchConfig, RestClient restClient) {
|
||||
return new ElasticsearchRestClient(elasticsearchConfig, restClient);
|
||||
}
|
||||
|
||||
@Bean("elasticsearchClientV2")
|
||||
@DependsOn("restHighLevelClient")
|
||||
public ElasticsearchClientV2 elasticsearchClientV2(ElasticsearchConfig elasticsearchConfig, RestHighLevelClient restHighLevelClient) {
|
||||
return new ElasticsearchClientV2(elasticsearchConfig, restHighLevelClient);
|
||||
}
|
||||
|
||||
public String getUserIndex() {
|
||||
return userIndex;
|
||||
}
|
||||
|
||||
public void setUserIndex(String userIndex) {
|
||||
this.userIndex = userIndex;
|
||||
}
|
||||
|
||||
public String getRoomIndex() {
|
||||
return roomIndex;
|
||||
}
|
||||
|
||||
public void setRoomIndex(String roomIndex) {
|
||||
this.roomIndex = roomIndex;
|
||||
}
|
||||
}
|
@@ -1,88 +0,0 @@
|
||||
package com.accompany.business.elasticsearch;
|
||||
|
||||
import com.accompany.business.config.ElasticsearchConfig;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestClientBuilder;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ElasticsearchClientV2 {
|
||||
private final Logger logger = LoggerFactory.getLogger(ElasticsearchRestClient.class);
|
||||
|
||||
private RestHighLevelClient restClient;
|
||||
|
||||
private final ElasticsearchConfig elasticsearchConfig;
|
||||
|
||||
//必须格式化这种格式,否则elasticsearch无法识别
|
||||
private final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
|
||||
private final String ES_LINE_BREAK = "\n";
|
||||
|
||||
public ElasticsearchClientV2(ElasticsearchConfig elasticsearchConfig, RestHighLevelClient restHighLevelClient){
|
||||
this.elasticsearchConfig = elasticsearchConfig;
|
||||
this.restClient = restHighLevelClient;
|
||||
}
|
||||
|
||||
public void init(){
|
||||
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
String username = elasticsearchConfig.getUsername();
|
||||
String password = elasticsearchConfig.getPassword();
|
||||
if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) {
|
||||
credentialsProvider.setCredentials(AuthScope.ANY,
|
||||
new UsernamePasswordCredentials(username, password));
|
||||
}
|
||||
RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(elasticsearchConfig.getHostName(), elasticsearchConfig.getPort()))
|
||||
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
|
||||
restClient = new RestHighLevelClient(restClientBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页搜索
|
||||
*
|
||||
* @param index 索引,类似数据库
|
||||
* @param queryBuilder 条件构造器,交给调用方自定义
|
||||
* @param sortBuilder 排序构造器,交给调用方自定义
|
||||
* @param page 页码
|
||||
* @param pageSize 页数
|
||||
* @return 返回结果的hits
|
||||
* @throws IOException
|
||||
*/
|
||||
public EsPage searchDataPage(String index, QueryBuilder queryBuilder, SortBuilder sortBuilder, Integer page, Integer pageSize) throws IOException {
|
||||
Assert.hasText(index, "index is empty");
|
||||
Assert.notNull(queryBuilder, "queryBuilder is null");
|
||||
// Assert.isTrue(page > 0, "page must be greater than or equal to 0");
|
||||
// Assert.isTrue(pageSize > 0, "pageSize must be greater than 0");
|
||||
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
// 是否进行分页
|
||||
if(page != null && pageSize != null) {
|
||||
searchSourceBuilder.from((page - 1) * pageSize).size(pageSize);
|
||||
}
|
||||
searchSourceBuilder.explain(true).query(queryBuilder).sort(sortBuilder);
|
||||
|
||||
SearchRequest searchRequest = new SearchRequest(new String[]{index}, searchSourceBuilder);
|
||||
|
||||
SearchResponse response = restClient.search(searchRequest, RequestOptions.DEFAULT);
|
||||
|
||||
Integer total = Long.valueOf(response.getHits().getTotalHits().value).intValue();
|
||||
return new EsPage(page, pageSize, total, response.getHits().getHits());
|
||||
}
|
||||
|
||||
}
|
@@ -1,255 +0,0 @@
|
||||
package com.accompany.business.elasticsearch;
|
||||
|
||||
import com.accompany.business.config.ElasticsearchConfig;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.nio.entity.NStringEntity;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ElasticsearchRestClient {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ElasticsearchRestClient.class);
|
||||
|
||||
private RestClient restClient;
|
||||
|
||||
private final ElasticsearchConfig elasticsearchConfig;
|
||||
|
||||
//必须格式化这种格式,否则elasticsearch无法识别
|
||||
private final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
|
||||
private final String ES_LINE_BREAK = "\n";
|
||||
|
||||
public ElasticsearchRestClient(ElasticsearchConfig elasticsearchConfig, RestClient restClient){
|
||||
this.elasticsearchConfig = elasticsearchConfig;
|
||||
this.restClient = restClient;
|
||||
}
|
||||
|
||||
public void init(){
|
||||
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
String username = elasticsearchConfig.getUsername();
|
||||
String password = elasticsearchConfig.getPassword();
|
||||
if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) {
|
||||
credentialsProvider.setCredentials(AuthScope.ANY,
|
||||
new UsernamePasswordCredentials(username, password));
|
||||
}
|
||||
restClient = RestClient.builder(new HttpHost(elasticsearchConfig.getHostName(), elasticsearchConfig.getPort()))
|
||||
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建索引
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public boolean createIndex(String index) throws IOException {
|
||||
logger.info("createIndex. index:{}", index);
|
||||
Assert.hasText(index, "index is empty");
|
||||
|
||||
String endpoint = "/" + index;
|
||||
Request request = new Request(ElasticsearchRequestMethod.PUT, endpoint);
|
||||
Response response = restClient.performRequest(request);
|
||||
return isRequestSuccess(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据添加,自定义ID
|
||||
*
|
||||
* @param index 索引,类似数据库
|
||||
* @param type 类型,类似表
|
||||
* @param id 数据ID
|
||||
* @param data 要增加的数据
|
||||
* @return
|
||||
*/
|
||||
public <T> boolean saveOrUpdate(String index, String type, String id, T data) throws IOException {
|
||||
logger.info("saveOrUpdate. index:{}, type:{}, id:{}", index, type, id);
|
||||
Assert.hasText(index, "index is empty");
|
||||
Assert.hasText(type, "type is empty");
|
||||
Assert.hasText(id, "id is empty");
|
||||
Assert.notNull(data, "data is null");
|
||||
|
||||
String endpoint = "/" + index + "/" + type + "/" + id;
|
||||
HttpEntity entity = new NStringEntity(gson.toJson(data), ContentType.APPLICATION_JSON);
|
||||
Request request = new Request(ElasticsearchRequestMethod.PUT, endpoint);
|
||||
request.setEntity(entity);
|
||||
Response response = restClient.performRequest(request);
|
||||
return isRequestSuccess(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新
|
||||
* @param index 索引,类似数据库
|
||||
* @param type 类型,类似表
|
||||
* @param dataList 数据集
|
||||
* @param idFunction 获取id的函数
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public <T> boolean bulkSaveOrUpdate(String index, String type, List<T> dataList, Function<T, String> idFunction) throws IOException {
|
||||
logger.info("bulkSaveOrUpdate. index:{}, type:{}, dataList size:{}", index, type, dataList.size());
|
||||
Assert.hasText(index, "index is empty");
|
||||
Assert.hasText(type, "type is empty");
|
||||
Assert.isTrue(!CollectionUtils.isEmpty(dataList), "dataList is empty");
|
||||
Assert.notNull(idFunction, "idFunction is null");
|
||||
|
||||
String endpoint = "/" + index + "/" + type + "/_bulk";
|
||||
String bulkRequestJson = buildBulkRequestJson(dataList, idFunction);
|
||||
HttpEntity entity = new NStringEntity(bulkRequestJson, ContentType.APPLICATION_JSON);
|
||||
Request request = new Request(ElasticsearchRequestMethod.POST, endpoint);
|
||||
request.setEntity(entity);
|
||||
Response response = restClient.performRequest(request);
|
||||
return isRequestSuccess(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造批量请求的json串
|
||||
* @param dataList
|
||||
* @param idFunction
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
private <T> String buildBulkRequestJson(List<T> dataList, Function<T, String> idFunction){
|
||||
StringBuilder builder = new StringBuilder();
|
||||
dataList.forEach(data -> {
|
||||
String id = idFunction.apply(data);
|
||||
Map<String, Object> map1 = Maps.newHashMap();
|
||||
map1.put("_id", id);
|
||||
Map<String, Object> map2 = Maps.newHashMap();
|
||||
map2.put(ElasticsearchBulkAction.INDEX, map1);
|
||||
builder.append(gson.toJson(map2) + ES_LINE_BREAK);
|
||||
builder.append(gson.toJson(data) + ES_LINE_BREAK);
|
||||
});
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ID删除数据
|
||||
*
|
||||
* @param index 索引,类似数据库
|
||||
* @param type 类型,类似表
|
||||
* @param id 数据ID
|
||||
*/
|
||||
public boolean deleteDataById(String index, String type, String id) throws IOException {
|
||||
logger.info("deleteDataById. index:{}, type:{}, id:{}", index, type, id);
|
||||
Assert.hasText(index, "index is empty");
|
||||
Assert.hasText(type, "type is empty");
|
||||
Assert.hasText(id, "id is empty");
|
||||
|
||||
String endpoint = "/" + index + "/" + type + "/" + id;
|
||||
Request request = new Request(ElasticsearchRequestMethod.DELETE, endpoint);
|
||||
Response response = restClient.performRequest(request);
|
||||
return isRequestSuccess(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ID查询数据
|
||||
*
|
||||
* @param index 索引,类似数据库
|
||||
* @param type 类型,类似表
|
||||
* @param id 数据ID
|
||||
*/
|
||||
public Map<String, Object> getDataById(String index, String type, String id) throws IOException {
|
||||
logger.info("getDataById. index:{}, type:{}, id:{}", index, type, id);
|
||||
Assert.hasText(index, "index is empty");
|
||||
Assert.hasText(type, "type is empty");
|
||||
Assert.hasText(id, "id is empty");
|
||||
|
||||
String endpoint = "/" + index + "/" + type + "/" + id;
|
||||
Request request = new Request(ElasticsearchRequestMethod.GET, endpoint);
|
||||
Response response = restClient.performRequest(request);
|
||||
if (!isRequestSuccess(response)){
|
||||
logger.error("getDataById error:{}", response);
|
||||
throw new RuntimeException(response.getStatusLine().toString());
|
||||
}
|
||||
String entityJson = EntityUtils.toString(response.getEntity());
|
||||
JSONObject entityJsonObject = JSONObject.parseObject(entityJson);
|
||||
return (Map<String, Object>) entityJsonObject.get("_source");
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索歌曲
|
||||
*
|
||||
* @param index 索引,类似数据库
|
||||
* @param type 类型,类似表
|
||||
* @param queryBuilder 条件构造器,交给调用方自定义
|
||||
* @param sortBuilder 排序构造器,交给调用方自定义
|
||||
* @param page 页码
|
||||
* @param pageSize 页数
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public EsPage searchDataPage(String index, String type, QueryBuilder queryBuilder, SortBuilder sortBuilder, Integer page, Integer pageSize) throws IOException {
|
||||
Assert.hasText(index, "index is empty");
|
||||
Assert.hasText(type, "type is empty");
|
||||
Assert.notNull(queryBuilder, "queryBuilder is null");
|
||||
// Assert.isTrue(page > 0, "page must be greater than or equal to 0");
|
||||
// Assert.isTrue(pageSize > 0, "pageSize must be greater than 0");
|
||||
|
||||
String endpoint = "/" + index + "/" + type + "/_search";
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
// 是否进行分页
|
||||
if(page != null && pageSize != null) {
|
||||
searchSourceBuilder.from((page - 1) * pageSize).size(pageSize);
|
||||
}
|
||||
searchSourceBuilder.explain(true).query(queryBuilder).sort(sortBuilder);
|
||||
String query = searchSourceBuilder.toString();
|
||||
HttpEntity queryEntity = new NStringEntity(query, ContentType.APPLICATION_JSON);
|
||||
Request request = new Request(ElasticsearchRequestMethod.GET, endpoint);
|
||||
request.setEntity(queryEntity);
|
||||
Response response = restClient.performRequest(request);
|
||||
if (!isRequestSuccess(response)){
|
||||
logger.error("searchDataPage error:{}", response);
|
||||
throw new RuntimeException(response.getStatusLine().toString());
|
||||
}
|
||||
String entityJson = EntityUtils.toString(response.getEntity());
|
||||
JSONObject entityJsonObject = JSONObject.parseObject(entityJson);
|
||||
JSONObject hitsJsonObject = entityJsonObject.getJSONObject("hits");
|
||||
Integer total = hitsJsonObject.getInteger("total");
|
||||
List<Map<String, Object>> hits = hitsJsonObject.getObject("hits", List.class);
|
||||
if (CollectionUtils.isEmpty(hits)){
|
||||
return new EsPage(page, pageSize, total, Lists.newArrayList());
|
||||
}
|
||||
List<Map<String, Object>> result = Lists.newArrayList();
|
||||
hits.forEach(hit -> result.add((Map<String, Object>) hit.get("_source")));
|
||||
return new EsPage(page, pageSize, total, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断请求是否成功
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
private boolean isRequestSuccess(Response response){
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode >= 200 && statusCode < 300){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -3,11 +3,7 @@ package com.accompany.business.service.room;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.accompany.business.config.ElasticsearchConfig;
|
||||
import com.accompany.business.constant.RoomTypeEnum;
|
||||
import com.accompany.business.elasticsearch.ElasticsearchClientV2;
|
||||
import com.accompany.business.elasticsearch.ElasticsearchRestClient;
|
||||
import com.accompany.business.elasticsearch.EsPage;
|
||||
import com.accompany.business.model.HallMember;
|
||||
import com.accompany.business.model.HallOperateRecord;
|
||||
import com.accompany.business.service.account.AccountBlockService;
|
||||
@@ -43,11 +39,7 @@ import com.google.common.reflect.TypeToken;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.search.sort.*;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -70,9 +62,6 @@ import static java.util.stream.Collectors.toList;
|
||||
@Service
|
||||
public class RoomSearchService extends BaseService {
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchRestClient esRestClient;
|
||||
|
||||
@Autowired
|
||||
private AccountBlockService accountBlockService;
|
||||
|
||||
@@ -94,22 +83,11 @@ public class RoomSearchService extends BaseService {
|
||||
@Autowired
|
||||
private RoomService roomService;
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchConfig elasticsearchConfig;
|
||||
@Autowired
|
||||
private ElasticsearchClientV2 elasticsearchClient;
|
||||
@Autowired
|
||||
private HallService hallService;
|
||||
@Autowired
|
||||
private HallManageService hallManageService;
|
||||
|
||||
private static final Integer SEARCH_TYPE_ROOM = 1;
|
||||
private static final Integer SEARCH_TYPE_USER = 2;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private UserBlackRecordService userBlackRecordService;
|
||||
|
||||
@Autowired
|
||||
private LevelService levelService;
|
||||
|
||||
@@ -203,34 +181,7 @@ public class RoomSearchService extends BaseService {
|
||||
return searchVos;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> query(String searchText, Integer type, Integer page, Integer pageSize) throws IOException {
|
||||
logger.info("searchText before:{}", searchText);
|
||||
//转译特殊字符
|
||||
searchText = HtmlUtils.htmlEscape(searchText, "UTF-8");
|
||||
logger.info("searchText after:{}", searchText);
|
||||
String esIndex;
|
||||
String esType;
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
||||
if (type == 1) {
|
||||
//搜索房间
|
||||
boolQuery.should(QueryBuilders.prefixQuery("erbanNo", searchText));
|
||||
boolQuery.should(QueryBuilders.prefixQuery("title", searchText));
|
||||
boolQuery.should(QueryBuilders.matchPhrasePrefixQuery("erbanNo", searchText));
|
||||
boolQuery.should(QueryBuilders.matchPhrasePrefixQuery("title", searchText));
|
||||
esIndex = Constant.ElasticsearchIndex.ROOM_INDEX;
|
||||
esType = Constant.ElasticsearchType.ROOM;
|
||||
} else {
|
||||
boolQuery.should(QueryBuilders.prefixQuery("erbanNo", searchText));
|
||||
boolQuery.should(QueryBuilders.prefixQuery("nick", searchText));
|
||||
boolQuery.should(QueryBuilders.matchPhrasePrefixQuery("erbanNo", searchText));
|
||||
boolQuery.should(QueryBuilders.matchPhrasePrefixQuery("nick", searchText));
|
||||
esIndex = Constant.ElasticsearchIndex.USER_INDEX;
|
||||
esType = Constant.ElasticsearchType.USER;
|
||||
}
|
||||
EsPage esPage = esRestClient.searchDataPage(esIndex, esType, boolQuery,
|
||||
SortBuilders.scriptSort(new Script("doc['erbanNo'].value.length()"), ScriptSortBuilder.ScriptSortType.NUMBER), page, pageSize);
|
||||
return esPage.getRecordList();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 过滤封禁的账号
|
||||
@@ -386,7 +337,7 @@ public class RoomSearchService extends BaseService {
|
||||
}
|
||||
|
||||
|
||||
public List<Long> filterCurrentRoomUid(Long roomUid, Integer pageNum, Integer pageSize, String cacheKey, Byte permitType) throws IOException {
|
||||
public List<Long> filterCurrentRoomUid(Long roomUid, Integer pageNum, Integer pageSize, String cacheKey, Byte permitType) {
|
||||
List<Long> pickUidList = new ArrayList<>();
|
||||
if (cacheKey == null || !jedisService.exits(cacheKey)) {
|
||||
// 注意!!!!:这个列表返回的
|
||||
@@ -457,79 +408,4 @@ public class RoomSearchService extends BaseService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<SearchVo> searchByEs(Long uid, String searchText, Integer searchType, Integer page, Integer pageSize, DeviceInfo deviceInfo) throws Exception {
|
||||
Users u = usersService.getUsersByUid(uid);
|
||||
if (null == u) {
|
||||
throw new ServiceException(BusiStatus.USERNOTEXISTS);
|
||||
}
|
||||
|
||||
List<Long> validUidList = new ArrayList<>();
|
||||
QueryBuilder queryBuilder;
|
||||
String index = null;
|
||||
if (SEARCH_TYPE_ROOM.equals(searchType)) {
|
||||
queryBuilder = genRoomSearchQueryCondition(u.getPartitionId(), validUidList, searchText);
|
||||
index = elasticsearchConfig.getRoomIndex();
|
||||
} else {
|
||||
queryBuilder =
|
||||
genUserSearchQueryCondition(u.getPartitionId(), validUidList, searchText);
|
||||
index = elasticsearchConfig.getUserIndex();
|
||||
}
|
||||
|
||||
SortBuilder sortBuilder = new FieldSortBuilder("erban_no_for_sort").order(SortOrder.ASC);
|
||||
|
||||
EsPage esPage = elasticsearchClient.searchDataPage(index, queryBuilder, sortBuilder, page, pageSize);
|
||||
|
||||
List<SearchVo> searchVos = convertEsPageToSearchVO(esPage);
|
||||
searchVos.forEach(searchVo -> searchVo.setRoomUid(null));
|
||||
searchVos = filterBlocked(searchVos);
|
||||
|
||||
return searchVos;
|
||||
}
|
||||
|
||||
private QueryBuilder genUserSearchQueryCondition(Integer partitionId, List<Long> validUidList, String searchText) {
|
||||
BoolQueryBuilder queryConditionBuilder = QueryBuilders.boolQuery()
|
||||
.mustNot(QueryBuilders.matchPhraseQuery("defUser", Constant.DefUser.ROBOT))
|
||||
.must(QueryBuilders.termQuery("partitionId", partitionId))
|
||||
.filter(
|
||||
QueryBuilders.boolQuery().should(QueryBuilders.matchPhraseQuery("nick", searchText))
|
||||
.should(QueryBuilders.matchPhraseQuery("erbanNo", searchText))
|
||||
);
|
||||
if (!CollectionUtils.isEmpty(validUidList)) {
|
||||
BoolQueryBuilder uidCondition = QueryBuilders.boolQuery();
|
||||
validUidList.forEach(uid -> {
|
||||
uidCondition.should(QueryBuilders.termQuery("uid", uid));
|
||||
});
|
||||
queryConditionBuilder.must(uidCondition);
|
||||
}
|
||||
return queryConditionBuilder;
|
||||
}
|
||||
|
||||
private QueryBuilder genRoomSearchQueryCondition(Integer partitionId, List<Long> validUidList, String searchText) {
|
||||
BoolQueryBuilder queryConditionBuilder = QueryBuilders.boolQuery()
|
||||
.mustNot(QueryBuilders.matchPhraseQuery("defUser", Constant.DefUser.ROBOT))
|
||||
.must(QueryBuilders.termQuery("valid", Constant.StatusV2.valid))
|
||||
.must(QueryBuilders.termQuery("partitionId", partitionId))
|
||||
.filter(
|
||||
QueryBuilders.boolQuery().should(QueryBuilders.matchPhraseQuery("title", searchText))
|
||||
.should(QueryBuilders.matchPhraseQuery("erbanNo", searchText))
|
||||
);
|
||||
if (!CollectionUtils.isEmpty(validUidList)) {
|
||||
BoolQueryBuilder uidCondition = QueryBuilders.boolQuery();
|
||||
validUidList.forEach(uid -> {
|
||||
uidCondition.should(QueryBuilders.termQuery("uid", uid));
|
||||
});
|
||||
queryConditionBuilder.must(uidCondition);
|
||||
}
|
||||
return queryConditionBuilder;
|
||||
}
|
||||
|
||||
private List<SearchVo> convertEsPageToSearchVO(EsPage esPage) {
|
||||
List<SearchVo> res = new ArrayList<>();
|
||||
Arrays.stream(esPage.getSearchHits()).forEach(item -> {
|
||||
SearchVo searchVo = JSONObject.parseObject(item.getSourceAsString(), SearchVo.class);
|
||||
res.add(searchVo);
|
||||
});
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@@ -45,12 +45,6 @@ public class SearchController extends BaseController {
|
||||
@Autowired
|
||||
private RoomSearchLogService roomSearchLogService;
|
||||
|
||||
// 搜索途径: elasticSearch
|
||||
private final static String ROOM_SEARCH_WAY_ES = "ES";
|
||||
// 搜索途径: 数据库
|
||||
private final static String ROOM_SEARCH_WAY_DB = "DB";
|
||||
private final static String DEFAULT_ROOM_SEARCH_WAY = ROOM_SEARCH_WAY_ES;
|
||||
|
||||
@Authorization
|
||||
@GetMapping(value = "/room")
|
||||
@ApiOperation("用户/房间搜索")
|
||||
@@ -72,15 +66,10 @@ public class SearchController extends BaseController {
|
||||
|
||||
Date now = new Date();
|
||||
|
||||
String roomSearchWay = sysConfService.getDefaultSysConfValueById(Constant.SysConfId.ROOM_SEARCH_WAY, DEFAULT_ROOM_SEARCH_WAY);
|
||||
log.info("search way: {}", roomSearchWay);
|
||||
|
||||
List<SearchVo> searchRooms = ROOM_SEARCH_WAY_DB.equalsIgnoreCase(roomSearchWay) ?
|
||||
//roomSearchService.searchV2(uid, key, type, page, pageSize, deviceInfo) :
|
||||
roomSearchService.search(uid, key, type, page, pageSize) :
|
||||
roomSearchService.searchByEs(uid, key, type, page, pageSize, deviceInfo);
|
||||
// 统一使用数据库搜索
|
||||
List<SearchVo> searchRooms = roomSearchService.search(uid, key, type, page, pageSize);
|
||||
|
||||
if (CollectionUtil.isNotEmpty(searchRooms)) {
|
||||
|
||||
roomSearchService.searchWrapper(UidContextHolder.get(), searchRooms);
|
||||
}
|
||||
roomSearchLogService.log(now, uid, deviceInfo, key, type, page, pageSize, searchRooms);
|
||||
|
@@ -58,15 +58,5 @@ rocketmq:
|
||||
group: peko-group
|
||||
sendMessageTimeout: 300000
|
||||
|
||||
## ES配置
|
||||
elasticsearch:
|
||||
clusterName: elasticsearch
|
||||
hostName: es-cn-2r42lphv9000nvr61.public.elasticsearch.aliyuncs.com
|
||||
port: 9200
|
||||
username: elastic
|
||||
password: xuanyin@es123
|
||||
roomIndex: yinyou_dev_room
|
||||
userIndex: yinyou_dev_users_202204121516
|
||||
|
||||
server:
|
||||
port: 8081
|
||||
|
@@ -1,37 +0,0 @@
|
||||
package servicetest;
|
||||
|
||||
import com.accompany.business.elasticsearch.ElasticsearchClientV2;
|
||||
import com.accompany.business.elasticsearch.EsPage;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.sort.FieldSortBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilder;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ElasticsearchClientV2Test extends CommonTest {
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchClientV2 elasticsearchClient;
|
||||
|
||||
@Test
|
||||
public void searchPageTest() throws IOException {
|
||||
String index = "66_dev_users";
|
||||
BoolQueryBuilder queryConditionBuilder = QueryBuilders.boolQuery()
|
||||
.mustNot(QueryBuilders.matchPhraseQuery("defUser", Constant.DefUser.ROBOT));
|
||||
|
||||
SortBuilder sortBuilder = new FieldSortBuilder("erban_no_for_sort").order(SortOrder.ASC);
|
||||
|
||||
EsPage esPage = elasticsearchClient.searchDataPage(index, queryConditionBuilder, sortBuilder, 1, 10);
|
||||
|
||||
System.out.println(esPage.getRecordCount());
|
||||
Arrays.stream(esPage.getSearchHits()).forEach(item -> {
|
||||
System.out.println(item.getSourceAsString());
|
||||
});
|
||||
}
|
||||
}
|
@@ -15,19 +15,19 @@ public class RoomSearchServiceTest extends CommonTest {
|
||||
private RoomSearchService roomSearchService;
|
||||
|
||||
@Test
|
||||
public void searchByEsTest() throws Exception {
|
||||
public void searchTest() throws Exception {
|
||||
String searchText = "凌芹";
|
||||
|
||||
List<SearchVo> searchVos = roomSearchService.searchByEs(null, searchText, 2, 1, 10, new DeviceInfo());
|
||||
List<SearchVo> searchVos = roomSearchService.search(null, searchText, 2, 1, 10);
|
||||
|
||||
System.out.println(JSONObject.toJSONString(searchVos));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchByEsTest_searchRoom() throws Exception {
|
||||
public void searchTest_searchRoom() throws Exception {
|
||||
String searchText = "野原";
|
||||
|
||||
List<SearchVo> searchVos = roomSearchService.searchByEs(null, searchText, 1, 1, 10, new DeviceInfo());
|
||||
List<SearchVo> searchVos = roomSearchService.search(null, searchText, 1, 1, 10);
|
||||
|
||||
System.out.println(JSONObject.toJSONString(searchVos));
|
||||
}
|
||||
|
@@ -56,7 +56,6 @@
|
||||
<validation-api.version>2.0.1.Final</validation-api.version>
|
||||
<aliyun-java-sdk-dysmsapi.version>1.1.0</aliyun-java-sdk-dysmsapi.version>
|
||||
<commons-fileupload.version>1.3</commons-fileupload.version>
|
||||
<elasticsearch.version>7.10.0</elasticsearch.version>
|
||||
<orika-core.version>1.5.4</orika-core.version>
|
||||
<spring-security-oauth2-autoconfigure.version>2.0.1.RELEASE</spring-security-oauth2-autoconfigure.version>
|
||||
<aliyun-java-sdk-cloudauth.version>1.2.0</aliyun-java-sdk-cloudauth.version>
|
||||
@@ -280,24 +279,6 @@
|
||||
<version>${hanlp.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch</artifactId>
|
||||
<version>${elasticsearch.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-client</artifactId>
|
||||
<version>${elasticsearch.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||
<version>${elasticsearch.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun.api.gateway</groupId>
|
||||
<artifactId>sdk-core-java</artifactId>
|
||||
@@ -485,16 +466,6 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- alibaba certification-->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.api.gateway</groupId>
|
||||
|
@@ -54,16 +54,6 @@ rocketmq:
|
||||
group: peko-group
|
||||
sendMessageTimeout: 300000
|
||||
|
||||
## ES配置
|
||||
elasticsearch:
|
||||
clusterName: elasticsearch
|
||||
hostName: es-cn-2r42lphv9000nvr61.public.elasticsearch.aliyuncs.com
|
||||
port: 9200
|
||||
username: elastic
|
||||
password: xuanyin@es123
|
||||
roomIndex: yinyou_dev_room
|
||||
userIndex: yinyou_dev_users_202204121516
|
||||
|
||||
server:
|
||||
port: 8081
|
||||
|
||||
|
@@ -3,9 +3,9 @@ spring:
|
||||
dynamic-datasource:
|
||||
master:
|
||||
poolName: master
|
||||
jdbcUrl: jdbc:mysql://124.156.164.187:3306/peko?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false&useSSL=false&useCursorFetch=true
|
||||
jdbcUrl: jdbc:mysql://129.226.62.202:3306/eparty?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false&useSSL=false&useCursorFetch=true
|
||||
username: root
|
||||
password: anan@dev##
|
||||
password: eparty@dev##
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
hikari:
|
||||
@@ -15,9 +15,9 @@ spring:
|
||||
max-lifetime: 7000
|
||||
slave:
|
||||
poolName: slave
|
||||
jdbcUrl: jdbc:mysql://124.156.164.187:3306/peko?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false&useSSL=false&useCursorFetch=true
|
||||
jdbcUrl: jdbc:mysql://129.226.62.202:3306/eparty?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false&useSSL=false&useCursorFetch=true
|
||||
username: root
|
||||
password: anan@dev##
|
||||
password: eparty@dev##
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
hikari:
|
||||
@@ -26,20 +26,20 @@ spring:
|
||||
connection-test-query: select 1
|
||||
max-lifetime: 7000
|
||||
redis:
|
||||
host: 124.156.164.187
|
||||
host: 129.226.62.202
|
||||
port: 6200
|
||||
maxTotal: 100
|
||||
maxIdle: 50
|
||||
maxWait: 2500
|
||||
testOnBorrow: true
|
||||
testOnReturn: true
|
||||
password: anan@dev@redis@#!
|
||||
password: pc8DphhaXwTe2jyv
|
||||
redisson:
|
||||
# file: classpath:redisson.yaml
|
||||
config: |
|
||||
singleServerConfig:
|
||||
address: redis://124.156.164.187:6200
|
||||
password: anan@dev@redis@#!
|
||||
address: redis://129.226.62.202:6200
|
||||
password: pc8DphhaXwTe2jyv
|
||||
connectionMinimumIdleSize: 4
|
||||
timeout: 10000
|
||||
threads: 8
|
||||
@@ -47,27 +47,9 @@ spring:
|
||||
codec: !<org.redisson.codec.JsonJacksonCodec> {}
|
||||
transportMode: "NIO"
|
||||
|
||||
##activemq 配置
|
||||
activemq:
|
||||
brokerUrl: tcp://124.156.164.187:61619
|
||||
user: system
|
||||
password: manager
|
||||
maxConnections: 50
|
||||
idleTimeout: 30000
|
||||
|
||||
## rocketmq 配置
|
||||
rocketmq:
|
||||
name-server: 124.156.164.187:9876
|
||||
name-server: 129.226.62.202:9876
|
||||
producer:
|
||||
group: peko-group
|
||||
sendMessageTimeout: 300000
|
||||
|
||||
## ES配置
|
||||
elasticsearch:
|
||||
clusterName: elasticsearch
|
||||
hostName: es-cn-2r42lphv9000nvr61.public.elasticsearch.aliyuncs.com
|
||||
port: 9200
|
||||
username: elastic
|
||||
password: xuanyin@es123
|
||||
roomIndex: yinyou_dev_room
|
||||
userIndex: yinyou_dev_users_202204121516
|
||||
group: eparty-group
|
||||
sendMessageTimeout: 300000
|
Reference in New Issue
Block a user