Closed animageofmine closed 7 years ago
Try 5.4.2, but also check out the quick start samples: https://github.com/sksamuel/elastic4s/tree/master/samples
I just tried it without any luck, I get the same error. Did you test the latest code against Elasticsearch (not elastic4s) 5.4?
Yes, look at the sample projects. They all use 5.4.2.
I looked at sample projects. The one that applies in my case is tcp-client-sbt. The only difference I see is scala version 2.12. In my case, I use 2.11.7. From the above error, it does not seem like a problem.
I am trying to perform aggregations, which is not working. Most of the other queries work fine.
Ok but when you opened the ticket you said you only posted code creating the client. Can you post up a full example of what fails and then I can help.
BTW, moving back to elastic4s 5.3.2 fixes the problem.
Here is an example of aggregation query from my code. Please note that the debugger never reaches here:
trait AggregationsService
{
def esClient: TcpClient
def aggregate(request: AggregateRequest): Future[Either[ErrorInfo, AggregateResponse]] =
{
// debugger never reaches here
val aggregateResponseFuture = esClient.execute{
search(indexName)
.size(0)
.aggregations(getAggregateQuery(request))
.query(constantScoreQuery(getFilterQuery(request).get))
}
// rest of the code
}
trait AggregationsModule {
lazy val aggregationService = new AggregationsService
with ElasticsearchProfile
}
It fails here.
trait ElasticsearchProfile {
val settings = Settings.builder().put("cluster.name", ElasticsearchClusterName).build()
// fails specifically here
val esClient = TcpClient.transport(settings, ElasticsearchClientUri(ElasticsearchHost, ElasticsearchPort))
}
This is exactly where it fails (SearchModule.java):
registerAggregation(new AggregationSpec(PercentilesAggregationBuilder.NAME, PercentilesAggregationBuilder::new,
PercentilesAggregationBuilder::parse)
.addResultReader(InternalTDigestPercentiles.NAME, InternalTDigestPercentiles::new)
.addResultReader(InternalHDRPercentiles.NAME, InternalHDRPercentiles::new));
build.sbt imports the following:
libraryDependencies ++= Seq(
"com.sksamuel.elastic4s" %% "elastic4s-core" % "5.4.2",
"com.sksamuel.elastic4s" %% "elastic4s-tcp" % "5.4.2",
)
It looks like there is some library that is not explicitly imported to ivy cache, hence the code cannot find the class.
It's prob a dependency issue like you surmise, but I can't help unless you can make a stand alone code snippet I can paste. Things like AggregationSpec
, registerAggregation
don't exist in the code you just pasted so I'd have to guess what they mean.
I should be able to create a code snippet. Sorry, I couldn't paste production code base completely.
I am a curious though because the issue didn't hit you. Anyway, I should be able to get back with a code snippet later in the evening today (I am located in Pacific Time Zone).
I understand completely about production code. If you can post up a self contained snippet that fails, I'll fix it 100%.
I'm in UTC btw, so prob be tomorrow night now.
Thanks Stephen. I think this can wait for one night since I changed the code and moved it back to 5.3.2.
Following is the code snippet I used to repro the bug in a separate project.
Let me know if you need more info.
Elasticsearch version: 5.3.2 Elastic4s version: 5.4.2
I imported index from here: https://www.elastic.co/guide/en/elasticsearch/reference/current/_exploring_your_data.html
package controllers
import com.sksamuel.elastic4s.{ElasticsearchClientUri, TcpClient}
import org.elasticsearch.common.settings.Settings
import play.api.mvc.{Action, Controller}
import com.sksamuel.elastic4s.ElasticDsl._
import com.sksamuel.elastic4s.searches.{RichSearchResponse, SearchDefinition}
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms
import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket
import org.elasticsearch.search.aggregations.metrics.max.InternalMax
import scala.concurrent._
import ExecutionContext.Implicits.global
object Elastic4sController extends Controller {
lazy val settings = Settings.builder().put("cluster.name", "localcluster").build()
// This is where code throws exception.
lazy val esClient = TcpClient.transport(settings, ElasticsearchClientUri("elasticsearch://localhost:9300"))
// Debugger never reaches here
def aggregationTest = Action.async {
esClient.execute {
search("bank")
.size(0)
.aggregations(sumAgg("agebalance", "balance"))
}.map {
(response: RichSearchResponse) =>
// Do something
println(response.ids)
Ok(views.html.index("successful"))
}
}
}
build.sbt
scalaVersion := "2.11.7"
libraryDependencies ++= Seq( jdbc , cache , ws , specs2 % Test )
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
resolvers += DefaultMavenRepository
resolvers += "Sonatype OSS" at "https://oss.sonatype.org/content/repositories/snapshots"
resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
resolvers += "Sonatype Releases" at "https://oss.sonatype.org/content/repositories/releases/"
libraryDependencies ++= Seq(
"com.sksamuel.elastic4s" %% "elastic4s-core" % "5.4.2",
"com.sksamuel.elastic4s" %% "elastic4s-tcp" % "5.4.2",
"com.sksamuel.elastic4s" %% "elastic4s-http" % "5.4.2",
)
build.properties
sbt.version=0.13.5
plugins.sbt
logLevel := Level.Warn
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
resolvers += "Typesafe Snapshots" at "http://repo.typesafe.com/typesafe/snapshots/"
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.2")
@sksamuel any update?
I can't duplicate your issue.
I've taken your snippets and made a project out of it. What you pasted didn't compile as you had a dangling comma in the sbt file and I removed the Controller
super class, as I have no idea how to run a play project, and replaced it with App
so its runnable.
https://github.com/sksamuel/elastic4s/tree/master/samples/issue907
I suspect your issue is that you have an older version of elastic lurking about on your classpath, and in that version the constructor it needs doesn't exist. Or just get rid of the TCP client and use the HTTP one exclusively.
Closing this as not heard otherwise.
Code fails to bootstrap TcpClient because it cannot register Aggregations.
Following is how I initialize it:
Scala version: 2.11.7 sbt version: 0.13.9 Elasticsearch Version: 5.4.0 Using play framework.
Please let me know if you need any more information. We were using elastic4s 5.0.1 before upgrade. I tried blowing up ivy cache, but no luck.