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