Last active
May 7, 2023 15:45
-
-
Save dacr/81ce436b83ec1c677749023c95dee84a to your computer and use it in GitHub Desktop.
Elasticsearch startup for test, experiences, proof of concept purposes. / published by https://github.com/dacr/code-examples-manager #7a5cdf23-0fa3-46ac-9567-3ff07105db90/79449fbadf177848a38fa83cb310a264e735fb0b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// summary : Elasticsearch startup for test, experiences, proof of concept purposes. | |
// keywords : scala, elasticsearch, cluster-runner | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 7a5cdf23-0fa3-46ac-9567-3ff07105db90 | |
// created-on : 2019-06-07T14:54:22Z | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc' | |
/* | |
Using [elasticsearch-cluster-runner](https://github.com/codelibs/elasticsearch-cluster-runner) | |
- Use Kibana-OSS edition if you need the kibana UI on top of this cluster | |
+ https://artifacts.elastic.co/downloads/kibana/kibana-oss-7.3.2-linux-x86_64.tar.gz | |
+ Kibana EE is not compatible with the embedded elasticsearch which is the OSS edition | |
+ Keep in sync Kibana-OSS and elasticsearch-cluster-runner releases | |
- This is a java dependency, so no prerequisites related to scala releases (or ammonite) | |
*/ | |
import $ivy.`org.codelibs:elasticsearch-cluster-runner:7.3.2.1` | |
//import $ivy.`org.codelibs:elasticsearch-cluster-runner:7.4.2.0` | |
import org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner, ElasticsearchClusterRunner.newConfigs | |
import org.elasticsearch.common.settings.Settings.Builder | |
// --- create runner instance | |
val runner = new ElasticsearchClusterRunner() | |
// --- create ES nodes | |
// --- by default 3 nodes are created 9201,9202,9203 | |
val configs = | |
newConfigs | |
.numOfNode(1) | |
.basePath("elastic-data") | |
runner.onBuild( | |
new ElasticsearchClusterRunner.Builder() { | |
override def build(number:Int, settingsBuilder:Builder):Unit = { | |
settingsBuilder.put("http.cors.enabled", true) | |
settingsBuilder.put("http.cors.allow-origin", "*") | |
settingsBuilder.put("cluster.routing.allocation.disk.threshold_enabled", false) | |
settingsBuilder.put("node.name", s"Node#$number") | |
settingsBuilder.put("http.port", 9200+number) | |
settingsBuilder.put("transport.port", "19300-19400") | |
} | |
} | |
).build(configs) | |
// --- Wait for nodes to be ready | |
//runner.ensureYellow() | |
val baseURL="http://127.0.0.1:9201" | |
println("***************************************************") | |
println("Ready, type <enter> to exit and stop nodes...") | |
println("Default storage is in /tmp/es-cluster*") | |
println("cheatsheet : https://elasticsearch-cheatsheet.jolicode.com/") | |
println(s""" - curl "$baseURL" """) | |
println(s""" - curl "$baseURL/_cat/indices" """) | |
println(s""" - curl "$baseURL/_all/_settings?pretty" """) | |
println(s""" - curl "$baseURL/_cluster/health?pretty" """) | |
println(s""" - curl "$baseURL/_cluster/health?pretty&wait_for_status=yellow&timeout=50s" """) | |
println(s""" - curl "$baseURL/_cluster/state" """) | |
println(s""" - curl "$baseURL/_cluster/state?human&pretty" """) | |
println(s""" - curl "$baseURL/_cluster/pending_tasks" """) | |
println(s""" - curl "$baseURL/_nodes" """) | |
println(s""" - curl "$baseURL/_nodes?pretty" """) | |
println(s""" - curl "$baseURL/_nodes/stats" """) | |
println(s""" - curl "$baseURL/_nodes/stats?pretty&human" | jq """) | |
println("***************************************************") | |
scala.io.StdIn.readLine() | |
// --- stop nodes | |
runner.close(); | |
// --- cleanup storage | |
//runner.clean() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment