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
9f0ecc2b
Commit
9f0ecc2b
authored
Feb 04, 2021
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update client
parent
931d4dd8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
50 deletions
+25
-50
build.sbt
build.sbt
+3
-3
ES.scala
src/main/scala/com.gmei.up/utils/ES.scala
+22
-47
No files found.
build.sbt
View file @
9f0ecc2b
...
...
@@ -36,9 +36,9 @@ lazy val root = (project in file("."))
libraryDependencies
+=
jsonNative
,
libraryDependencies
+=
jsonJackson
,
libraryDependencies
+=
"com.sksamuel.elastic4s"
%%
"elastic4s-http"
%
"6.7.8"
,
//
libraryDependencies += esCore,
//
libraryDependencies += esJava,
//
libraryDependencies += "com.sksamuel.elastic4s" %% "elastic4s-http" % "6.7.8",
libraryDependencies
+=
esCore
,
libraryDependencies
+=
esJava
,
libraryDependencies
+=
flinkCore
,
libraryDependencies
+=
flinkScala
,
...
...
src/main/scala/com.gmei.up/utils/ES.scala
View file @
9f0ecc2b
...
...
@@ -2,21 +2,21 @@ package com.gmei.up.utils
import
scala.collection.mutable.ListBuffer
import
scala.util.Try
// import com.sksamuel.elastic4s.http.{ JavaClient, HttpClient }
import
com.sksamuel.elastic4s.ElasticClient
import
com.sksamuel.elastic4s.http.JavaClient
import
org.apache.http.HttpHost
import
org.apache.http.auth.
{
AuthScope
,
UsernamePasswordCredentials
}
import
org.apache.http.impl.client.BasicCredentialsProvider
import
org.apache.http.impl.nio.client.HttpAsyncClientBuilder
import
org.elasticsearch.client.RestClient
import
org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback
import
com.sksamuel.elastic4s.http.ElasticDsl._
import
com.sksamuel.elastic4s.http.ElasticClient
// import com.sksamuel.elastic4s.requests.searches.{ SearchRequest, SearchResponse }
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
// import org.json4s.jackson.Serialization.write
// import scala.concurrent._
// import scala.concurrent.duration._
// import ExecutionContext.Implicits.global
...
...
@@ -31,15 +31,13 @@ object ESClient {
httpClientBuilder
.
setDefaultCredentialsProvider
(
credentialsProvider
)
}
// ElasticClient
def
create
(
hostname
:
String
,
port
:
Int
,
username
:
String
,
password
:
String
)
:
ElasticClient
=
{
val
restClient
=
RestClient
.
builder
(
new
HttpHost
(
hostname
,
port
,
"http"
))
.
setHttpClientConfigCallback
(
new
ElasticCredentials
(
username
,
password
))
.
build
()
ElasticClient
.
fromRestClient
(
restClient
)
// ElasticClient(JavaClient.fromRestClient(restClient))
ElasticClient
(
JavaClient
.
fromRestClient
(
restClient
))
}
}
...
...
@@ -57,51 +55,28 @@ object ES {
// TODO read from config
val
client
:
ElasticClient
=
ESClient
.
create
(
"172.16.52.33"
,
9200
,
"elastic"
,
"gengmei!@#"
)
// val bb = multi(
// search("gm-dbmw-diary-read").source(s"""${diaryQuery}"""),
// search("gm-dbmw-tractate-read").source(tractateQuery)
// )
// println(bb.show)
// println(diaryQuery)
// println(tractateQuery)
// // TODO remove await
// val resp = client.execute(bb).await
val
bb
=
multi
(
search
(
"gm-dbmw-diary-read"
).
source
(
s
"""${diaryQuery}"""
),
search
(
"gm-dbmw-tractate-read"
).
source
(
tractateQuery
)
)
// // println(resp)
println
(
bb
.
show
)
println
(
diaryQuery
)
println
(
tractateQuery
)
// val a = resp.result.to[Character]
// TODO remove await
val
resp
=
client
.
execute
(
bb
).
await
// println("%%%%%%%%%%%")
// println(a.size)
// a.foreach { x =>
// println(x.id, x.index, x.projects)
// }
// println("%%%%%%%%%%%")
// println(resp)
// resp
val
a
=
resp
.
result
.
to
[
Character
]
val
a
=
s
"""
{
"query": {
"bool": {
"must": [
{ "term": { "is_online": true } },
{ "range": { "content_level": { "gte": 3 } } }
]
println
(
"%%%%%%%%%%%"
)
println
(
a
.
size
)
a
.
foreach
{
x
=>
println
(
x
.
id
,
x
.
index
,
x
.
projects
)
}
},
"size": 10
}
"""
.
stripMargin
val
resp
=
client
.
execute
{
search
(
"gm-dbmw-diary-read"
).
source
(
a
)
}.
await
println
(
resp
)
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