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
e965f9e5
Commit
e965f9e5
authored
Feb 04, 2021
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add printer
parent
803ec69a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
7 deletions
+19
-7
ES.scala
src/main/scala/com.gmei.up/utils/ES.scala
+19
-7
No files found.
src/main/scala/com.gmei.up/utils/ES.scala
View file @
e965f9e5
package
com.gmei.up.utils
import
scala.collection.mutable.ListBuffer
import
scala.util.Try
import
com.sksamuel.elastic4s.ElasticClient
import
com.sksamuel.elastic4s.http.JavaClient
import
org.apache.http.HttpHost
...
...
@@ -11,6 +12,7 @@ import org.elasticsearch.client.RestClient
import
org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback
import
com.sksamuel.elastic4s.requests.searches.
{
SearchRequest
,
SearchResponse
}
import
com.sksamuel.elastic4s.ElasticDsl._
import
com.sksamuel.elastic4s.
{
HitReader
,
Hit
}
import
org.json4s.JsonDSL._
import
org.json4s.jackson.JsonMethods._
import
org.json4s.JObject
...
...
@@ -40,17 +42,20 @@ object ESClient {
}
object
ES
{
case
class
Character
(
id
:
String
)
implicit
object
CharacterHitReader
extends
HitReader
[
Character
]
{
override
def
read
(
hit
:
Hit
)
:
Try
[
Character
]
=
{
val
source
=
hit
.
sourceAsMap
Try
(
Character
(
source
(
"id"
).
toString
))
}
}
def
test
(
diaryQuery
:
String
,
tractateQuery
:
String
)
=
{
// TODO read from config
val
client
:
ElasticClient
=
ESClient
.
create
(
"172.16.52.33"
,
9200
,
"elastic"
,
"gengmei!@#"
)
val
a
=
multi
(
search
(
"gm-dbmw-diary-read"
).
source
(
diaryQuery
),
search
(
"gm-dbmw-tractate-read"
).
source
(
tractateQuery
)
)
println
(
a
.
toString
())
// TODO remove await
val
resp
=
client
.
execute
(
multi
(
...
...
@@ -61,6 +66,13 @@ object ES {
.
await
// println(resp)
val
a
=
resp
.
result
.
to
[
Character
]
println
(
"%%%%%%%%%%%"
)
a
.
foreach
(
x
=>
println
(
x
.
id
))
println
(
"%%%%%%%%%%%"
)
resp
}
...
...
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