Skip to content

Instantly share code, notes, and snippets.

@jto
Forked from zxamplez/CODE
Last active December 14, 2015 09:38
Show Gist options
  • Save jto/5065817 to your computer and use it in GitHub Desktop.
Save jto/5065817 to your computer and use it in GitHub Desktop.
Create an #elasticsearch local node in a #playframework app
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2013 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
trait ElasticSearch {
import org.elasticsearch.node._
import org.elasticsearch.node.NodeBuilder._
val ELASTIC_URL = "http://localhost:9200"
val INDEX_URL = ELASTIC_URL + "/examples/gists"
val SEARCH_URL = INDEX_URL + "/_search"
private var node: Option[Node] = None
def start(implicit app: Application) {
import org.elasticsearch.common.settings._
import org.elasticsearch.common.io.stream._
import java.io._
play.Logger.info("Starting ES")
import org.elasticsearch.common.settings.loader.SettingsLoader
val settings = Play.resourceAsStream("elasticsearch.yaml").map{ s =>
ImmutableSettings.settingsBuilder().loadFromStream("elasticsearch.yaml", s).build
}
val n = nodeBuilder()
.clusterName("play_by_example")
.local(true)
node = Some(settings.map(n.settings _).getOrElse(n).node)
}
def stop() {
play.Logger.info("Stopping ES")
for(n <- node) n.stop
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment