Skip to content

Instantly share code, notes, and snippets.

@bigwheel
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigwheel/df9d0fc6dd429c26333f to your computer and use it in GitHub Desktop.
Save bigwheel/df9d0fc6dd429c26333f to your computer and use it in GitHub Desktop.
import com.sksamuel.elastic4s.ElasticClient
import com.sksamuel.elastic4s.ElasticDsl._
import com.sksamuel.elastic4s.ElasticsearchClientUri
import org.elasticsearch.common.settings.ImmutableSettings
import org.elasticsearch.node.NodeBuilder._
import scala.collection.JavaConverters._
object Main {
private def transportClient = {
val settings = ImmutableSettings.settingsBuilder.
put("cluster.name", "my-cluster-name").
build
val uri = ElasticsearchClientUri(
"elasticsearch://" + List(51, 52, 53).map(ip => s"192.168.0.${ip}:9300").mkString(",")
)
ElasticClient.remote(settings, uri)
}
def main(args: Array[String]): Unit = {
try {
val client = transportClient
def searchInfinitely() = {
(0 to 100).foreach { times =>
def pow(base: Long, times: Int): Long = times match {
case 0 => 1
case _ => base * pow(base, times - 1)
}
(1L to pow(2, times)).foreach { _ =>
val response = client.execute {
search in "index1" query "あ" sourceInclude "id"
}.await
if (response.getFailedShards != 0)
println(s"${response.getFailedShards}のシャードで検索に失敗しました")
Thread.sleep(1)
}
println(s"${pow(2, times) * 2}-1回終了")
}
}
(1 to 5).par.foreach { _ => searchInfinitely }
} catch {
case e: Throwable =>
e.printStackTrace
} finally {
//client.close
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment