Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
brandkbs2
Overview
Overview
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
shenjunjie
brandkbs2
Commits
c15766a5
Commit
c15766a5
authored
Jul 15, 2024
by
陈健智
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
searchRecord调整2
parent
454bccf4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
46 deletions
+45
-46
src/main/java/com/zhiwei/brandkbs2/es/EsClientDao.java
+45
-46
No files found.
src/main/java/com/zhiwei/brandkbs2/es/EsClientDao.java
View file @
c15766a5
...
@@ -60,8 +60,6 @@ public class EsClientDao {
...
@@ -60,8 +60,6 @@ public class EsClientDao {
"brandkbs_cache_maps"
,
"brandkbs_mark_cache_maps"
,
"channel_influence"
,
"ind_full_text"
,
"url"
,
"question_url"
,
"answer_url"
};
"brandkbs_cache_maps"
,
"brandkbs_mark_cache_maps"
,
"channel_influence"
,
"ind_full_text"
,
"url"
,
"question_url"
,
"answer_url"
};
private
static
final
Long
ONE_HOUR
=
60
*
60
*
1000L
;
private
static
final
Long
ONE_HOUR
=
60
*
60
*
1000L
;
private
static
final
Long
HALF_HOUR
=
ONE_HOUR
/
2
;
// 滚动查询超时时间
// 滚动查询超时时间
private
static
final
TimeValue
TIME_VALUE
=
TimeValue
.
timeValueMinutes
(
8
);
private
static
final
TimeValue
TIME_VALUE
=
TimeValue
.
timeValueMinutes
(
8
);
...
@@ -105,34 +103,12 @@ public class EsClientDao {
...
@@ -105,34 +103,12 @@ public class EsClientDao {
long
startTime
=
calendar
.
getTime
().
getTime
();
long
startTime
=
calendar
.
getTime
().
getTime
();
List
<
Long
[]>
cutTimes
=
Tools
.
cutTimeRange
(
startTime
,
endTime
,
ONE_HOUR
);
List
<
Long
[]>
cutTimes
=
Tools
.
cutTimeRange
(
startTime
,
endTime
,
ONE_HOUR
);
List
<
CompletableFuture
<
Pair
<
Long
[],
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>>>>
futures
=
new
ArrayList
<>(
cutTimes
.
size
());
List
<
CompletableFuture
<
Pair
<
Long
[],
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>>>>
futures
=
new
ArrayList
<>(
cutTimes
.
size
());
try
{
cutTimes
.
forEach
(
times
->
futures
.
add
(
CompletableFuture
.
supplyAsync
(()
->
searchRecord
(
times
[
0
],
times
[
1
]),
executor
)));
cutTimes
.
forEach
(
times
->
futures
.
add
(
CompletableFuture
.
supplyAsync
(()
->
{
CompletableFuture
.
allOf
(
futures
.
toArray
(
new
CompletableFuture
[
0
])).
whenComplete
((
r
,
e
)
->
{
try
{
futures
.
forEach
(
f
->
{
return
searchRecord
(
times
[
0
],
times
[
1
]);
res
.
add
(
f
.
join
());
}
catch
(
IOException
e
)
{
});
throw
new
RuntimeException
(
e
);
}).
join
();
}
},
executor
)));
CompletableFuture
.
allOf
(
futures
.
toArray
(
new
CompletableFuture
[
0
])).
whenComplete
((
r1
,
e1
)
->
futures
.
forEach
(
f
->
res
.
add
(
f
.
join
()))).
join
();
}
catch
(
Exception
e
){
log
.
error
(
"error-searchRecordRecentDay-oneHour,跨度调整为半小时再重试"
,
e
);
List
<
Long
[]>
halfCutTimes
=
Tools
.
cutTimeRange
(
startTime
,
endTime
,
HALF_HOUR
);
futures
.
clear
();
res
.
clear
();
try
{
halfCutTimes
.
forEach
(
times
->
futures
.
add
(
CompletableFuture
.
supplyAsync
(()
->
{
try
{
return
searchRecord
(
times
[
0
],
times
[
1
]);
}
catch
(
IOException
e2
)
{
throw
new
RuntimeException
(
e2
);
}
},
executor
)));
CompletableFuture
.
allOf
(
futures
.
toArray
(
new
CompletableFuture
[
0
])).
whenComplete
((
r2
,
e2
)
->
futures
.
forEach
(
f
->
res
.
add
(
f
.
join
()))).
join
();
log
.
error
(
"跨度半小时重试成功"
);
}
catch
(
Exception
exception
){
log
.
error
(
"error-searchRecordRecentDay-oneHour,跨度半小时重试失败"
,
exception
);
}
}
return
res
;
return
res
;
}
}
...
@@ -194,24 +170,47 @@ public class EsClientDao {
...
@@ -194,24 +170,47 @@ public class EsClientDao {
return
retryTemplate
.
execute
(
context
->
searchScroll
(
sourceBuilder
));
return
retryTemplate
.
execute
(
context
->
searchScroll
(
sourceBuilder
));
}
}
private
Pair
<
Long
[],
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>>
searchRecord
(
long
startTime
,
long
endTime
)
throws
IOException
{
private
Pair
<
Long
[],
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>>
searchRecord
(
long
startTime
,
long
endTime
)
{
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>
res
=
new
HashMap
<>();
Map
<
ChannelIndex
,
ChannelIndex
.
Record
>
res
=
new
HashMap
<>();
QueryBuilder
queryBuilder
=
QueryBuilders
.
rangeQuery
(
"mtime"
).
gte
(
startTime
).
lt
(
endTime
);
try
{
List
<
JSONObject
>
results
=
searchScroll
(
queryBuilder
,
10000
,
CHANNEL_RECORD_FETCH_SOURCE
);
List
<
JSONObject
>
results
=
new
ArrayList
<>();
for
(
Map
<
String
,
Object
>
result
:
results
)
{
try
{
for
(
ChannelIndex
channelIndex
:
ChannelIndex
.
createChannelIndexes
(
result
))
{
QueryBuilder
queryBuilder
=
QueryBuilders
.
rangeQuery
(
"mtime"
).
gte
(
startTime
).
lt
(
endTime
);
res
.
compute
(
channelIndex
,
(
k
,
v
)
->
{
results
=
searchScroll
(
queryBuilder
,
10000
,
CHANNEL_RECORD_FETCH_SOURCE
);
if
(
null
==
v
)
{
}
catch
(
Exception
e
){
v
=
new
ChannelIndex
.
Record
();
log
.
error
(
"searchRecord-搜索阶段出错-时间分段重试开始"
,
e
);
}
// 时间分段查询
try
{
long
midTime
=
startTime
+
(
endTime
-
startTime
)
/
2
;
return
v
.
mergeRecord
(
new
ChannelIndex
.
Record
(
result
));
try
{
}
catch
(
Exception
e
)
{
QueryBuilder
queryBuilder1
=
QueryBuilders
.
rangeQuery
(
"mtime"
).
gte
(
startTime
).
lt
(
midTime
);
log
.
error
(
"searchRecord-error-id:{}"
,
result
.
get
(
"id"
),
e
);
results
.
addAll
(
searchScroll
(
queryBuilder1
,
10000
,
CHANNEL_RECORD_FETCH_SOURCE
));
return
null
;
}
catch
(
Exception
e1
){
}
log
.
error
(
"searchRecord分段查询出错,时间范围:{}-{}"
,
startTime
,
midTime
,
e1
);
});
}
try
{
QueryBuilder
queryBuilder2
=
QueryBuilders
.
rangeQuery
(
"mtime"
).
gte
(
midTime
).
lt
(
endTime
);
results
.
addAll
(
searchScroll
(
queryBuilder2
,
10000
,
CHANNEL_RECORD_FETCH_SOURCE
));
}
catch
(
Exception
e2
){
log
.
error
(
"searchRecord分段查询出错,时间范围:{}-{}"
,
midTime
,
endTime
,
e2
);
}
}
for
(
Map
<
String
,
Object
>
result
:
results
)
{
for
(
ChannelIndex
channelIndex
:
ChannelIndex
.
createChannelIndexes
(
result
))
{
res
.
compute
(
channelIndex
,
(
k
,
v
)
->
{
if
(
null
==
v
)
{
v
=
new
ChannelIndex
.
Record
();
}
try
{
return
v
.
mergeRecord
(
new
ChannelIndex
.
Record
(
result
));
}
catch
(
Exception
e
)
{
log
.
error
(
"searchRecord-error-id:{}"
,
result
.
get
(
"id"
),
e
);
return
null
;
}
});
}
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"searchRecord-"
,
e
);
}
}
log
.
info
(
"startTime:{},endTime:{},size:{}"
,
DF
.
format
(
startTime
),
DF
.
format
(
endTime
),
res
.
size
());
log
.
info
(
"startTime:{},endTime:{},size:{}"
,
DF
.
format
(
startTime
),
DF
.
format
(
endTime
),
res
.
size
());
return
Pair
.
of
(
new
Long
[]{
startTime
,
endTime
},
res
);
return
Pair
.
of
(
new
Long
[]{
startTime
,
endTime
},
res
);
...
...
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