优化ES搜索,修复关键词如果包含特殊字符导致被分词问题
This commit is contained in:
+44
-7
@@ -5,6 +5,8 @@ import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||
import xtools.app.common.config.AppCommonConfig;
|
||||
|
||||
/**
|
||||
@@ -42,7 +44,12 @@ public class EsSysLog {
|
||||
/**
|
||||
* 日志追踪ID
|
||||
*/
|
||||
@Field(type = FieldType.Text)
|
||||
@MultiField(
|
||||
mainField = @Field(type = FieldType.Text),
|
||||
otherFields = {
|
||||
@InnerField(suffix = "keyword", type = FieldType.Keyword)
|
||||
}
|
||||
)
|
||||
private String traceId;
|
||||
|
||||
/**
|
||||
@@ -72,25 +79,45 @@ public class EsSysLog {
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
@Field(type = FieldType.Text)
|
||||
@MultiField(
|
||||
mainField = @Field(type = FieldType.Text),
|
||||
otherFields = {
|
||||
@InnerField(suffix = "keyword", type = FieldType.Keyword)
|
||||
}
|
||||
)
|
||||
private String appName;
|
||||
|
||||
/**
|
||||
* 本机IP
|
||||
*/
|
||||
@Field(type = FieldType.Text)
|
||||
@MultiField(
|
||||
mainField = @Field(type = FieldType.Text),
|
||||
otherFields = {
|
||||
@InnerField(suffix = "keyword", type = FieldType.Keyword)
|
||||
}
|
||||
)
|
||||
private String localIp;
|
||||
|
||||
/**
|
||||
* 运行端口
|
||||
*/
|
||||
@Field(type = FieldType.Text)
|
||||
@MultiField(
|
||||
mainField = @Field(type = FieldType.Text),
|
||||
otherFields = {
|
||||
@InnerField(suffix = "keyword", type = FieldType.Keyword)
|
||||
}
|
||||
)
|
||||
private String port;
|
||||
|
||||
/**
|
||||
* 日志标题
|
||||
*/
|
||||
@Field(type = FieldType.Text)
|
||||
@MultiField(
|
||||
mainField = @Field(type = FieldType.Text),
|
||||
otherFields = {
|
||||
@InnerField(suffix = "keyword", type = FieldType.Keyword)
|
||||
}
|
||||
)
|
||||
private String title;
|
||||
|
||||
/**
|
||||
@@ -108,13 +135,23 @@ public class EsSysLog {
|
||||
/**
|
||||
* 请求IP
|
||||
*/
|
||||
@Field(type = FieldType.Text)
|
||||
@MultiField(
|
||||
mainField = @Field(type = FieldType.Text),
|
||||
otherFields = {
|
||||
@InnerField(suffix = "keyword", type = FieldType.Keyword)
|
||||
}
|
||||
)
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 请求URI
|
||||
*/
|
||||
@Field(type = FieldType.Text)
|
||||
@MultiField(
|
||||
mainField = @Field(type = FieldType.Text),
|
||||
otherFields = {
|
||||
@InnerField(suffix = "keyword", type = FieldType.Keyword)
|
||||
}
|
||||
)
|
||||
private String uri;
|
||||
|
||||
/**
|
||||
|
||||
+7
-7
@@ -121,19 +121,19 @@ public class EsSysLogServiceImpl implements SysLogService, BaseParams {
|
||||
JSONArray must = new JSONArray();
|
||||
EsQueryUtils.setTimeRange(must, "logTime", req.getLogTimeRange());
|
||||
|
||||
EsQueryUtils.setMatchPhrase(must, "traceId", req.getTraceId());
|
||||
EsQueryUtils.setWildcard(must, "traceId", req.getTraceId(), true);
|
||||
EsQueryUtils.setMatchPhrase(must, "logType", req.getLogType());
|
||||
EsQueryUtils.setMatchPhrase(must, "logLevel", req.getLogLevel());
|
||||
|
||||
EsQueryUtils.setWildcard(must, "title", req.getTitle());
|
||||
EsQueryUtils.setWildcard(must, "ip", req.getIp());
|
||||
EsQueryUtils.setWildcard(must, "uri", req.getUri());
|
||||
EsQueryUtils.setWildcard(must, "title.keyword", req.getTitle(), true);
|
||||
EsQueryUtils.setWildcard(must, "ip.keyword", req.getIp(), true);
|
||||
EsQueryUtils.setWildcard(must, "uri.keyword", req.getUri(), true);
|
||||
|
||||
EsQueryUtils.setMatchPhrase(must, "threadType", req.getThreadType());
|
||||
|
||||
EsQueryUtils.setWildcard(must, "appName", req.getAppName());
|
||||
EsQueryUtils.setWildcard(must, "localIp", req.getLocalIp());
|
||||
EsQueryUtils.setWildcard(must, "port", req.getPort());
|
||||
EsQueryUtils.setWildcard(must, "appName.keyword", req.getAppName(), true);
|
||||
EsQueryUtils.setWildcard(must, "localIp.keyword", req.getLocalIp(), true);
|
||||
EsQueryUtils.setWildcard(must, "port.keyword", req.getPort(), true);
|
||||
|
||||
JSONObject query = JSONObject.of("bool", JSONObject.of("must", must));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user