es-client
Lightweight Scala Elasticsearch client implemented using Elasticsearch REST API.
Table of contents
Goals
- Speed up unit testing when using Spark
- Enable switching between Spark execution engine and Scala collections depending on use case, especially size of data without changing implementation
Getting started
Include dependencies
"com.github.piotr-kalanski" % "es-client_2.11" % "0.2.0"
or
<dependency>
<groupId>com.github.piotr-kalanski</groupId>
<artifactId>es-client_2.11</artifactId>
<version>0.2.0</version>
</dependency>
Create Elasticsearch repository
import com.datawizards.esclient.repository.ElasticsearchRepositoryImpl
val repository = new ElasticsearchRepositoryImpl("http://localhost:9200")
Examples
Create index
val mapping =
"""{
| "mappings" : {
| "Person" : {
| "properties" : {
| "name" : {"type" : "string"},
| "age" : {"type" : "integer"}
| }
| }
| }
|}""".stripMargin
val indexName = "persontest"
repository.createIndex(indexName, mapping)
Check if index exists
repository.indexExists(indexName)
Delete index
repository.deleteIndex(indexName)
Writing and reading documents
case class Person(name: String, age: Int)
repository.write("people", "person", "1", Person("p1", 20))
repository.read[Person]("people", "person", "1")