Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
fdbbbbc7
Commit
fdbbbbc7
authored
Jul 14, 2021
by
郭武斌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*)修改ES查询为空时异常
parent
30205672
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
14 deletions
+62
-14
ElasticSearchClientConfig.java
...boot/module/jcs/biz/config/ElasticSearchClientConfig.java
+46
-0
ESAlertCalledService.java
...oot/module/jcs/biz/service/impl/ESAlertCalledService.java
+16
-14
No files found.
amos-boot-module/amos-boot-module-biz/amos-boot-module-jcs-biz/src/main/java/com/yeejoin/amos/boot/module/jcs/biz/config/ElasticSearchClientConfig.java
0 → 100644
View file @
fdbbbbc7
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jcs
.
biz
.
config
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.http.HttpHost
;
import
org.apache.http.client.config.RequestConfig
;
import
org.elasticsearch.client.RestClient
;
import
org.elasticsearch.client.RestClientBuilder
;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
public
class
ElasticSearchClientConfig
{
@Value
(
"${spring.elasticsearch.rest.uris}"
)
private
String
uris
;
@Bean
@Qualifier
(
"highLevelClient"
)
public
RestHighLevelClient
restHighLevelClient
()
{
try
{
String
url
=
uris
.
replace
(
"http://"
,
""
);
final
String
[]
parts
=
StringUtils
.
split
(
url
,
":"
);
HttpHost
httpHost
=
new
HttpHost
(
parts
[
0
],
Integer
.
parseInt
(
parts
[
1
]),
"http"
);
RestClientBuilder
builder
=
RestClient
.
builder
(
httpHost
);
builder
.
setRequestConfigCallback
(
new
RestClientBuilder
.
RequestConfigCallback
()
{
// 该方法接收一个RequestConfig.Builder对象,对该对象进行修改后然后返回。
@Override
public
RequestConfig
.
Builder
customizeRequestConfig
(
RequestConfig
.
Builder
requestConfigBuilder
)
{
return
requestConfigBuilder
.
setConnectTimeout
(
5000
*
1000
)
// 连接超时(默认为1秒)
.
setSocketTimeout
(
6000
*
1000
);
// 套接字超时(默认为30秒)//更改客户端的超时限制默认30秒现在改为100*1000分钟
}
});
// 调整最大重试超时时间(默认为30秒).setMaxRetryTimeoutMillis(60000);
return
new
RestHighLevelClient
(
builder
);
}
catch
(
Exception
e
)
{
throw
new
IllegalStateException
(
"Invalid ES nodes "
+
"property '"
+
uris
+
"'"
,
e
);
}
}
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-jcs-biz/src/main/java/com/yeejoin/amos/boot/module/jcs/biz/service/impl/ESAlertCalledService.java
View file @
fdbbbbc7
...
@@ -27,12 +27,6 @@ import com.yeejoin.amos.boot.module.jcs.api.entity.AlertCalled;
...
@@ -27,12 +27,6 @@ import com.yeejoin.amos.boot.module.jcs.api.entity.AlertCalled;
import
com.yeejoin.amos.boot.module.jcs.api.entity.ESAlertCalled
;
import
com.yeejoin.amos.boot.module.jcs.api.entity.ESAlertCalled
;
import
com.yeejoin.amos.boot.module.jcs.api.enums.AlertStatusEnum
;
import
com.yeejoin.amos.boot.module.jcs.api.enums.AlertStatusEnum
;
import
com.yeejoin.amos.boot.module.jcs.biz.dao.ESAlertCalledRepository
;
import
com.yeejoin.amos.boot.module.jcs.biz.dao.ESAlertCalledRepository
;
import
javax.annotation.PostConstruct
;
import
java.util.Date
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
/**
*
*
* <pre>
* <pre>
...
@@ -274,18 +268,26 @@ public class ESAlertCalledService {
...
@@ -274,18 +268,26 @@ public class ESAlertCalledService {
//过滤条件
//过滤条件
.
withQuery
(
boolMust
);
.
withQuery
(
boolMust
);
// 对高亮词条进行操作
SearchHits
<
ESAlertCalled
>
searchHits
=
elasticsearchTemplate
.
search
(
queryBuilder
.
build
(),
ESAlertCalled
.
class
);
List
<
ESAlertCalledDto
>
list
=
new
LinkedList
<>();
List
<
ESAlertCalledDto
>
list
=
new
LinkedList
<>();
for
(
SearchHit
searchHit
:
searchHits
.
getSearchHits
())
long
totle
=
0
;
try
{
SearchHits
<
ESAlertCalled
>
searchHits
=
elasticsearchTemplate
.
search
(
queryBuilder
.
build
(),
ESAlertCalled
.
class
);
for
(
SearchHit
searchHit
:
searchHits
.
getSearchHits
())
{
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
searchHit
.
getContent
());
ESAlertCalledDto
eSAlertCalled
=
JSONObject
.
toJavaObject
(
jsonObject
,
ESAlertCalledDto
.
class
);
list
.
add
(
eSAlertCalled
);
}
totle
=
searchHits
.
getTotalHits
();
}
catch
(
Exception
e
)
{
{
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
searchHit
.
getContent
());
// TODO: handle exception
ESAlertCalledDto
eSAlertCalled
=
JSONObject
.
toJavaObject
(
jsonObject
,
ESAlertCalledDto
.
class
);
list
.
add
(
eSAlertCalled
);
}
}
result
.
setRecords
(
list
);
result
.
setRecords
(
list
);
result
.
setTotal
(
searchHits
.
getTotalHits
()
);
result
.
setTotal
(
totle
);
return
result
;
return
result
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment