Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
streamingUserPortrait
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
赵威
streamingUserPortrait
Commits
17140e3b
Commit
17140e3b
authored
Feb 04, 2021
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try multi search
parent
41acdc4e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
34 deletions
+89
-34
Main.scala
src/main/scala/com.gmei.up/Main.scala
+9
-7
ES.scala
src/main/scala/com.gmei.up/utils/ES.scala
+80
-27
No files found.
src/main/scala/com.gmei.up/Main.scala
View file @
17140e3b
...
@@ -29,6 +29,11 @@ class UserInfoDeserializationSchema extends KafkaDeserializationSchema[UserInfo]
...
@@ -29,6 +29,11 @@ class UserInfoDeserializationSchema extends KafkaDeserializationSchema[UserInfo]
object
Main
{
object
Main
{
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
// println("###############")
// val query = ES.generateTractateQuery(List("光子嫩肤", "水光针"), List("丰胸", "胸部塑身"))
// println(query)
// println("###############")
val
env
=
StreamExecutionEnvironment
.
getExecutionEnvironment
val
env
=
StreamExecutionEnvironment
.
getExecutionEnvironment
// TODO read from config
// TODO read from config
...
@@ -47,17 +52,14 @@ object Main {
...
@@ -47,17 +52,14 @@ object Main {
val
stream
:
DataStream
[
UserInfo
]
=
env
.
addSource
(
kafkaConsumer
)
val
stream
:
DataStream
[
UserInfo
]
=
env
.
addSource
(
kafkaConsumer
)
// println("###############")
// ES.generateDiaryQuery(-1, List("光子嫩肤", "水光针"), List("丰胸", "胸部塑身"))
// println("###############")
stream
.
map
{
user
=>
stream
.
map
{
user
=>
println
(
user
.
deviceId
)
println
(
user
.
deviceId
)
val
projects
=
user
.
projects
.
toList
val
projects
=
user
.
projects
.
toList
val
secondDemands
=
user
.
secondDemands
.
toList
val
secondDemands
=
user
.
secondDemands
.
toList
if
((
projects
.
size
>
0
)
&&
(
secondDemands
.
size
>
0
))
{
if
((
projects
.
size
>
0
)
||
(
secondDemands
.
size
>
0
))
{
val
query
=
ES
.
generateDiaryQuery
(-
1
,
projects
,
secondDemands
)
val
diaryQuery
=
ES
.
generateDiaryQuery
(
projects
,
secondDemands
,
-
1
)
ES
.
test
(
query
)
val
tractateQuery
=
ES
.
generateTractateQuery
(
projects
,
secondDemands
)
ES
.
test
(
diaryQuery
,
tractateQuery
)
}
}
println
(
"########################"
)
println
(
"########################"
)
}
}
...
...
src/main/scala/com.gmei.up/utils/ES.scala
View file @
17140e3b
...
@@ -40,39 +40,29 @@ object ESClient {
...
@@ -40,39 +40,29 @@ object ESClient {
}
}
object
ES
{
object
ES
{
def
test
(
q
uery
:
String
)
=
{
def
test
(
diaryQuery
:
String
,
tractateQ
uery
:
String
)
=
{
val
client
:
ElasticClient
=
ESClient
.
create
(
"172.16.52.33"
,
9200
,
"elastic"
,
"gengmei!@#"
)
val
client
:
ElasticClient
=
ESClient
.
create
(
"172.16.52.33"
,
9200
,
"elastic"
,
"gengmei!@#"
)
val
json
=
"""
{
"query": {
"bool": {
"filter": [
{
"terms": { "tags_v3": ["光子嫩肤", "水光针"] }
}
]
}
}
}
"""
;
val
resp
=
client
.
execute
{
val
resp
=
client
search
(
"gm-dbmw-diary-read"
).
source
(
query
)
.
execute
(
}.
await
multi
(
search
(
"gm-dbmw-diary-read"
).
source
(
diaryQuery
),
search
(
"gm-dbmw-tractate-read"
).
source
(
tractateQuery
)
)
)
.
await
println
(
resp
)
println
(
resp
)
resp
resp
}
}
// SearchRequest
// SearchRequest
def
generateDiaryQuery
(
def
generateDiaryQuery
(
projects
:
List
[
String
],
secondDemands
:
List
[
String
],
cityId
:
Int
=
-
1
)
:
String
=
{
cityId
:
Int
=
-
1
,
val
size
=
10
projects
:
List
[
String
]
=
List
.
empty
[
String
],
secondDemands
:
List
[
String
]
=
List
.
empty
[
String
]
)
:
String
=
{
val
size
=
100
val
includes
=
List
(
"id"
,
"tags_v3"
)
val
includes
=
List
(
"id"
,
"tags_v3"
)
// TODO read
val
functions
=
new
ListBuffer
[
JObject
]()
val
functions
=
new
ListBuffer
[
JObject
]()
val
shoulds
=
new
ListBuffer
[
JObject
]()
val
shoulds
=
new
ListBuffer
[
JObject
]()
if
(
projects
.
size
>
0
)
{
if
(
projects
.
size
>
0
)
{
...
@@ -92,7 +82,7 @@ object ES {
...
@@ -92,7 +82,7 @@ object ES {
shoulds
+=
(
"terms"
->
(
"second_demands"
->
secondDemands
))
shoulds
+=
(
"terms"
->
(
"second_demands"
->
secondDemands
))
}
}
val
res
=
s
"""
val
query
=
s
"""
{
{
"query": {
"query": {
"function_score": {
"function_score": {
...
@@ -167,8 +157,71 @@ object ES {
...
@@ -167,8 +157,71 @@ object ES {
}
}
"""
"""
// println("diary query\n")
// println("diary query:")
// println(res)
// println(query)
res
query
}
def
generateTractateQuery
(
projects
:
List
[
String
],
secondDemands
:
List
[
String
])
:
String
=
{
val
size
=
10
val
includes
=
List
(
"id"
,
"tags_v3"
)
val
functions
=
new
ListBuffer
[
JObject
]()
val
shoulds
=
new
ListBuffer
[
JObject
]()
if
(
projects
.
size
>
0
)
{
val
promotes
:
List
[
JObject
]
=
List
((
"terms"
->
(
"tags_v3"
->
projects
)),
(
"term"
->
(
"is_promote"
->
true
)))
functions
+=
(
"filter"
->
(
"bool"
->
(
"must"
->
promotes
)))
~
(
"weight"
->
60
)
functions
+=
(
"filter"
->
(
"terms"
->
{
"tags_v3"
->
projects
}))
~
(
"weight"
->
50
)
shoulds
+=
(
"terms"
->
(
"tags_v3"
->
projects
))
}
if
(
secondDemands
.
size
>
0
)
{
functions
+=
(
"filter"
->
(
"terms"
->
(
"second_demands"
->
secondDemands
)))
~
(
"weight"
->
40
)
shoulds
+=
(
"terms"
->
(
"second_demands"
->
secondDemands
))
}
val
query
=
s
"""
{
"query": {
"function_score": {
"functions": ${pretty(render(functions.toList))},
"boost_mode": "replace",
"score_mode": "max",
"query": {
"bool": {
"should": ${pretty(render(shoulds.toList))},
"minimum_should_match": 1,
"must": [
{
"term": {
"is_online": "true"
}
},
{
"terms": {
"content_level": [6, 5, 4, 3.5, 3]
}
}
],
"must_not": [
{ "term": { "status": 4 } },
{ "term": { "show_by_index": 2 } }
]
}
}
}
},
"size": ${size},
"_source": ${pretty(render(includes))}
}
"""
// println("tractate query:")
// println(query)
query
}
}
}
}
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