Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
# cache: 'sbt'
- name: Setup sbt launcher
uses: sbt/setup-sbt@v1
- name: Set vm.max_map_count
run: sudo sysctl -w vm.max_map_count=262144
- name: Run tests
run: sbt test

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
uses: sbt/setup-sbt@v1
- name: Formatting
run: sbt scalafmtSbtCheck scalafmtCheck test:scalafmtCheck
- name: Set vm.max_map_count
run: sudo sysctl -w vm.max_map_count=262144
- name: Run tests & Coverage Report
run: sbt coverage test coverageReport coverageAggregate
- name: Upload coverage to Codecov
Expand Down
8 changes: 6 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ThisBuild / organization := "app.softnetwork"

name := "elastic"

ThisBuild / version := "7.17.29"
ThisBuild / version := Versions.elasticSearch

ThisBuild / scalaVersion := "2.12.18"

Expand Down Expand Up @@ -75,7 +75,11 @@ lazy val rest = project.in(file("rest"))

lazy val testKit = project.in(file("testkit"))
.configs(IntegrationTest)
.settings(Defaults.itSettings)
.settings(
Defaults.itSettings,
app.softnetwork.Info.infoSettings
)
.enablePlugins(BuildInfoPlugin)
.dependsOn(
rest % "compile->compile;test->test;it->it"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ trait IndexApi { _: RefreshApi =>

def indexAsync(index: String, id: String, source: String)(implicit
ec: ExecutionContext
): Future[Boolean]
): Future[Boolean] = {
Future {
this.index(index, id, source)
}
}
}

trait UpdateApi { _: RefreshApi =>
Expand Down Expand Up @@ -241,7 +245,11 @@ trait UpdateApi { _: RefreshApi =>

def updateAsync(index: String, id: String, source: String, upsert: Boolean)(implicit
ec: ExecutionContext
): Future[Boolean]
): Future[Boolean] = {
Future {
this.update(index, id, source, upsert)
}
}
}

trait DeleteApi { _: RefreshApi =>
Expand Down Expand Up @@ -279,7 +287,11 @@ trait DeleteApi { _: RefreshApi =>

def deleteAsync(uuid: String, index: String)(implicit
ec: ExecutionContext
): Future[Boolean]
): Future[Boolean] = {
Future {
this.delete(uuid, index)
}
}

}

Expand Down Expand Up @@ -330,9 +342,9 @@ trait BulkApi { _: RefreshApi with SettingsApi =>
* | balance | | bulk |
* | |------->| |
* +----------+ +----------+
* | |
* | |
* | |
* | |
* | |
* | |
* +---------+ | |
* | |<-----------' |
* | merge | |
Expand Down Expand Up @@ -502,7 +514,11 @@ trait BulkApi { _: RefreshApi with SettingsApi =>
}

trait CountApi {
def countAsync(query: JSONQuery)(implicit ec: ExecutionContext): Future[Option[Double]]
def countAsync(query: JSONQuery)(implicit ec: ExecutionContext): Future[Option[Double]] = {
Future {
this.count(query)
}
}

def count(query: JSONQuery): Option[Double]

Expand All @@ -527,7 +543,11 @@ trait GetApi {
id: String,
index: Option[String] = None,
maybeType: Option[String] = None
)(implicit m: Manifest[U], ec: ExecutionContext, formats: Formats): Future[Option[U]]
)(implicit m: Manifest[U], ec: ExecutionContext, formats: Formats): Future[Option[U]] = {
Future {
this.get[U](id, index, maybeType)
}
}
}

trait SearchApi {
Expand All @@ -538,13 +558,26 @@ trait SearchApi {

def searchAsync[U](
sqlQuery: SQLQuery
)(implicit m: Manifest[U], ec: ExecutionContext, formats: Formats): Future[List[U]]
)(implicit m: Manifest[U], ec: ExecutionContext, formats: Formats): Future[List[U]] = Future(
this.search[U](sqlQuery)
)

def searchWithInnerHits[U, I](sqlQuery: SQLQuery, innerField: String)(implicit
m1: Manifest[U],
m2: Manifest[I],
formats: Formats
): List[(U, List[I])]
): List[(U, List[I])] = {
sqlQuery.search match {
case Some(searchRequest) =>
val indices = collection.immutable.Seq(searchRequest.sources: _*)
val jsonQuery = JSONQuery(searchRequest.query, indices)
searchWithInnerHits(jsonQuery, innerField)
case None =>
throw new IllegalArgumentException(
s"SQL query ${sqlQuery.query} does not contain a valid search request"
)
}
}

def searchWithInnerHits[U, I](jsonQuery: JSONQuery, innerField: String)(implicit
m1: Manifest[U],
Expand All @@ -554,7 +587,23 @@ trait SearchApi {

def multiSearch[U](
sqlQuery: SQLQuery
)(implicit m: Manifest[U], formats: Formats): List[List[U]]
)(implicit m: Manifest[U], formats: Formats): List[List[U]] = {
sqlQuery.multiSearch match {
case Some(multiSearchRequest) =>
val jsonQueries: JSONQueries = JSONQueries(
collection.immutable
.Seq(multiSearchRequest.requests.map { searchRequest =>
JSONQuery(searchRequest.query, collection.immutable.Seq(searchRequest.sources: _*))
}: _*)
.toList
)
multiSearch[U](jsonQueries)
case None =>
throw new IllegalArgumentException(
s"SQL query ${sqlQuery.query} does not contain a valid search request"
)
}
}

def multiSearch[U](
jsonQueries: JSONQueries
Expand All @@ -564,12 +613,27 @@ trait SearchApi {
m1: Manifest[U],
m2: Manifest[I],
formats: Formats
): List[List[(U, List[I])]]
): List[List[(U, List[I])]] = {
sqlQuery.multiSearch match {
case Some(multiSearchRequest) =>
val jsonQueries: JSONQueries = JSONQueries(
collection.immutable
.Seq(multiSearchRequest.requests.map { searchRequest =>
JSONQuery(searchRequest.query, collection.immutable.Seq(searchRequest.sources: _*))
}: _*)
.toList
)
multiSearchWithInnerHits[U, I](jsonQueries, innerField)
case None =>
throw new IllegalArgumentException(
s"SQL query ${sqlQuery.query} does not contain a valid search request"
)
}
}

def multiSearchWithInnerHits[U, I](jsonQueries: JSONQueries, innerField: String)(implicit
m1: Manifest[U],
m2: Manifest[I],
formats: Formats
): List[List[(U, List[I])]]

}
3 changes: 0 additions & 3 deletions project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ object Versions {

val elastic4s = "7.17.4"

val jest = "6.3.1"

val log4j = "2.8.2"

val testContainers = "1.18.0"
Expand All @@ -34,5 +32,4 @@ object Versions {

val gson = "2.8.0"

val rest = "7.17.29" // rest high level client
}
4 changes: 2 additions & 2 deletions rest/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ val jacksonExclusions = Seq(

val rest = Seq(
"org.elasticsearch" % "elasticsearch" % Versions.elasticSearch exclude ("org.apache.logging.log4j", "log4j-api"),
"org.elasticsearch.client" % "elasticsearch-rest-high-level-client" % Versions.rest exclude ("org.elasticsearch", "elasticsearch"),
"org.elasticsearch.client" % "elasticsearch-rest-client" % Versions.rest
"org.elasticsearch.client" % "elasticsearch-rest-high-level-client" % Versions.elasticSearch exclude ("org.elasticsearch", "elasticsearch"),
"org.elasticsearch.client" % "elasticsearch-rest-client" % Versions.elasticSearch
).map(_.excludeAll(jacksonExclusions: _*))

libraryDependencies ++= rest
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.language.implicitConversions
import scala.util.{Failure, Success, Try}

@deprecated("Use app.softnetwork.elastic.client.java.ElasticsearchClientApi instead", "8.x")
trait RestHighLevelClientApi
extends ElasticClientApi
with RestHighLevelClientIndicesApi
Expand Down Expand Up @@ -620,23 +621,6 @@ trait RestHighLevelClientSearchApi extends SearchApi with RestHighLevelClientCom
promise.future
}

override def searchWithInnerHits[U, I](sqlQuery: SQLQuery, innerField: String)(implicit
m1: Manifest[U],
m2: Manifest[I],
formats: Formats
): List[(U, List[I])] = {
sqlQuery.search match {
case Some(searchRequest) =>
val indices = collection.immutable.Seq(searchRequest.sources: _*)
val jsonQuery = JSONQuery(searchRequest.query, indices)
searchWithInnerHits(jsonQuery, innerField)
case None =>
throw new IllegalArgumentException(
s"SQL query ${sqlQuery.query} does not contain a valid search request"
)
}
}

override def searchWithInnerHits[U, I](jsonQuery: JSONQuery, innerField: String)(implicit
m1: Manifest[U],
m2: Manifest[I],
Expand Down Expand Up @@ -667,26 +651,6 @@ trait RestHighLevelClientSearchApi extends SearchApi with RestHighLevelClientCom
}
}

override def multiSearch[U](
sqlQuery: SQLQuery
)(implicit m: Manifest[U], formats: Formats): List[List[U]] = {
sqlQuery.multiSearch match {
case Some(multiSearchRequest) =>
val jsonQueries: JSONQueries = JSONQueries(
collection.immutable
.Seq(multiSearchRequest.requests.map { searchRequest =>
JSONQuery(searchRequest.query, collection.immutable.Seq(searchRequest.sources: _*))
}: _*)
.toList
)
multiSearch[U](jsonQueries)
case None =>
throw new IllegalArgumentException(
s"SQL query ${sqlQuery.query} does not contain a valid search request"
)
}
}

override def multiSearch[U](
jsonQueries: JSONQueries
)(implicit m: Manifest[U], formats: Formats): List[List[U]] = {
Expand Down Expand Up @@ -720,28 +684,6 @@ trait RestHighLevelClientSearchApi extends SearchApi with RestHighLevelClientCom
}
}

override def multiSearchWithInnerHits[U, I](sqlQuery: SQLQuery, innerField: String)(implicit
m1: Manifest[U],
m2: Manifest[I],
formats: Formats
): List[List[(U, List[I])]] = {
sqlQuery.multiSearch match {
case Some(multiSearchRequest) =>
val jsonQueries: JSONQueries = JSONQueries(
collection.immutable
.Seq(multiSearchRequest.requests.map { searchRequest =>
JSONQuery(searchRequest.query, collection.immutable.Seq(searchRequest.sources: _*))
}: _*)
.toList
)
multiSearchWithInnerHits[U, I](jsonQueries, innerField)
case None =>
throw new IllegalArgumentException(
s"SQL query ${sqlQuery.query} does not contain a valid search request"
)
}
}

override def multiSearchWithInnerHits[U, I](jsonQueries: JSONQueries, innerField: String)(implicit
m1: Manifest[U],
m2: Manifest[I],
Expand Down Expand Up @@ -796,20 +738,13 @@ trait RestHighLevelClientBulkApi
import bulkItem._
val request = action match {
case BulkAction.UPDATE =>
val r = new UpdateRequest(index, if (id.isEmpty) null else id.get)
new UpdateRequest(index, id.orNull)
.doc(body, XContentType.JSON)
.docAsUpsert(true)
// parent.foreach(r.parent)
r
case BulkAction.DELETE =>
val r = new DeleteRequest(index).id(id.getOrElse("_all"))
// parent.foreach(r.parent)
r
new DeleteRequest(index).id(id.getOrElse("_all"))
case _ =>
val r = new IndexRequest(index).source(body, XContentType.JSON)
id.foreach(r.id)
// parent.foreach(r.parent)
r
new IndexRequest(index).source(body, XContentType.JSON).id(id.orNull)
}
request
}
Expand Down
Loading