|
@@ -5,7 +5,6 @@ import cn.hutool.core.util.StrUtil;
|
|
import com.ruoyi.common.constant.DefineConstant;
|
|
import com.ruoyi.common.constant.DefineConstant;
|
|
import com.ruoyi.framework.config.properties.ElasticSearchConfig;
|
|
import com.ruoyi.framework.config.properties.ElasticSearchConfig;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.http.HttpHost;
|
|
import org.apache.http.HttpHost;
|
|
import org.elasticsearch.action.ActionListener;
|
|
import org.elasticsearch.action.ActionListener;
|
|
import org.elasticsearch.action.DocWriteRequest;
|
|
import org.elasticsearch.action.DocWriteRequest;
|
|
@@ -31,13 +30,18 @@ import org.elasticsearch.client.indices.CreateIndexRequest;
|
|
import org.elasticsearch.client.indices.CreateIndexResponse;
|
|
import org.elasticsearch.client.indices.CreateIndexResponse;
|
|
import org.elasticsearch.client.indices.GetIndexRequest;
|
|
import org.elasticsearch.client.indices.GetIndexRequest;
|
|
import org.elasticsearch.common.Strings;
|
|
import org.elasticsearch.common.Strings;
|
|
-import org.elasticsearch.common.settings.Settings;
|
|
|
|
import org.elasticsearch.common.unit.DistanceUnit;
|
|
import org.elasticsearch.common.unit.DistanceUnit;
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
-import org.elasticsearch.common.xcontent.XContentType;
|
|
|
|
import org.elasticsearch.core.TimeValue;
|
|
import org.elasticsearch.core.TimeValue;
|
|
-import org.elasticsearch.index.query.*;
|
|
|
|
|
|
+import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
|
+import org.elasticsearch.index.query.GeoDistanceQueryBuilder;
|
|
|
|
+import org.elasticsearch.index.query.MatchQueryBuilder;
|
|
|
|
+import org.elasticsearch.index.query.PrefixQueryBuilder;
|
|
|
|
+import org.elasticsearch.index.query.QueryBuilders;
|
|
|
|
+import org.elasticsearch.index.query.RangeQueryBuilder;
|
|
|
|
+import org.elasticsearch.index.query.TermQueryBuilder;
|
|
|
|
+import org.elasticsearch.index.query.WildcardQueryBuilder;
|
|
import org.elasticsearch.search.SearchHit;
|
|
import org.elasticsearch.search.SearchHit;
|
|
import org.elasticsearch.search.SearchHits;
|
|
import org.elasticsearch.search.SearchHits;
|
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
@@ -50,7 +54,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
-import org.springframework.util.MultiValueMap;
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.PostConstruct;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -59,7 +62,6 @@ import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* ES客户端
|
|
* ES客户端
|
|
@@ -105,7 +107,7 @@ public class ElasticSearchClient {
|
|
/**
|
|
/**
|
|
* 创建索引
|
|
* 创建索引
|
|
*
|
|
*
|
|
- * @param index
|
|
|
|
|
|
+ * @param index 索引名
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public boolean createIndex(String index) throws IOException {
|
|
public boolean createIndex(String index) throws IOException {
|
|
@@ -190,7 +192,8 @@ public class ElasticSearchClient {
|
|
* 更新文档内容
|
|
* 更新文档内容
|
|
*
|
|
*
|
|
* @param indexName 索引名称
|
|
* @param indexName 索引名称
|
|
- * @param id
|
|
|
|
|
|
+ * @param id id
|
|
|
|
+ * @param paramMap paramMap
|
|
*/
|
|
*/
|
|
public void updateDocument(String indexName, String id, Map<String, Object> paramMap) {
|
|
public void updateDocument(String indexName, String id, Map<String, Object> paramMap) {
|
|
|
|
|
|
@@ -222,10 +225,9 @@ public class ElasticSearchClient {
|
|
* 删除文档数据
|
|
* 删除文档数据
|
|
*
|
|
*
|
|
* @param indexName 索引名称
|
|
* @param indexName 索引名称
|
|
- * @param id
|
|
|
|
- * @throws Exception
|
|
|
|
|
|
+ * @param id id
|
|
*/
|
|
*/
|
|
- public void deleteDocument(String indexName, String id) throws Exception {
|
|
|
|
|
|
+ public void deleteDocument(String indexName, String id) {
|
|
DeleteRequest deleteRequest = new DeleteRequest(indexName, id);
|
|
DeleteRequest deleteRequest = new DeleteRequest(indexName, id);
|
|
// 主分片执行删除的超时时长
|
|
// 主分片执行删除的超时时长
|
|
deleteRequest.timeout(TimeValue.timeValueMinutes(2));
|
|
deleteRequest.timeout(TimeValue.timeValueMinutes(2));
|
|
@@ -448,7 +450,7 @@ public class ElasticSearchClient {
|
|
boolQueryBuilder.must(termQueryBuilder);
|
|
boolQueryBuilder.must(termQueryBuilder);
|
|
}
|
|
}
|
|
} else if (value instanceof Collection) {
|
|
} else if (value instanceof Collection) {
|
|
- Collection<? extends Object> collectionValue = (Collection<? extends Object>) value;
|
|
|
|
|
|
+ Collection<?> collectionValue = (Collection<?>) value;
|
|
//此处使用了多值条件
|
|
//此处使用了多值条件
|
|
boolQueryBuilder.must(QueryBuilders.termsQuery(key, collectionValue));
|
|
boolQueryBuilder.must(QueryBuilders.termsQuery(key, collectionValue));
|
|
} else {
|
|
} else {
|
|
@@ -579,7 +581,7 @@ public class ElasticSearchClient {
|
|
* 索引创建前,判断索引是否存在
|
|
* 索引创建前,判断索引是否存在
|
|
*/
|
|
*/
|
|
public static Boolean isIndexExist(String checkIndex) {
|
|
public static Boolean isIndexExist(String checkIndex) {
|
|
- Boolean flag = false;
|
|
|
|
|
|
+ boolean flag = false;
|
|
try {
|
|
try {
|
|
GetIndexRequest getIndexRequest = new GetIndexRequest(checkIndex);
|
|
GetIndexRequest getIndexRequest = new GetIndexRequest(checkIndex);
|
|
getIndexRequest.local(false);
|
|
getIndexRequest.local(false);
|