Skip to content

Commit

Permalink
Add close to ElasticClient, fixed path.home bug
Browse files Browse the repository at this point in the history
The need for path.home to be configured is meh, it's documented in the
open issue on ES here:

	elastic/elasticsearch#13155

for now using UUID class to create a unique directory to store data in.
  • Loading branch information
EdgeCaseBerg committed Feb 9, 2016
1 parent ce015b4 commit 26a8535
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,2 +1,2 @@
target

tmp
24 changes: 23 additions & 1 deletion src/main/scala/ElasticClients.scala
Expand Up @@ -5,6 +5,7 @@ import org.elasticsearch.client.transport._
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport._
import java.net.{ InetAddress, InetSocketAddress }
import java.util.UUID

/** This is to illustrate how you can construct a Transport Client in ES 2.2.0
*
Expand All @@ -19,6 +20,10 @@ trait TcpClient extends ElasticClient {

val client: Client = new TransportClient.Builder().settings(settings).build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300))

def close {
client.close()
}
}

import org.elasticsearch.node._
Expand All @@ -33,9 +38,18 @@ import org.elasticsearch.node.NodeBuilder._
trait NodeClient extends ElasticClient {
val node: Node = nodeBuilder()
.clusterName("elasticsearch")
.settings(Settings.settingsBuilder()
.put("http.enabled", false)
.put("path.home", "tmp/" + UUID.randomUUID())
.put("index.store.type", "memory"))
.client(true)
.node();
val client: Client = node.client();

def close {
client.close()
node.close()
}
}

/** This is to illustrate how to start a local node and supply a client
Expand All @@ -48,8 +62,16 @@ trait NodeClient extends ElasticClient {
trait LocalNodeClient extends ElasticClient {
val node: Node = nodeBuilder()
.clusterName("elasticsearch")
.settings(Settings.settingsBuilder().put("http.enabled", false))
.settings(Settings.settingsBuilder()
.put("http.enabled", false)
.put("path.home", "tmp/" + UUID.randomUUID())
.put("index.store.type", "memory"))
.local(true)
.node();
val client: Client = node.client();

def close {
client.close()
node.close()
}
}
1 change: 1 addition & 0 deletions src/main/scala/ElasticSearchService.scala
Expand Up @@ -6,6 +6,7 @@ import org.elasticsearch.index.query._
/** Extend this trait and provide a configured client, then mix it into ElasticSearchService */
trait ElasticClient {
val client: Client
def close: Unit
}

/** Helper Class to make our service interface a little bit easier */
Expand Down

0 comments on commit 26a8535

Please sign in to comment.