scala driver for elasticsearch
Switch branches/tags
Clone or download
bsadeh Merge pull request #42 from martinb3/master
Bump to support elasticsearch 1.1.1
Latest commit ed4d950 May 14, 2014


Scala driver for ElasticSearch

Scalastic is an interface for ElasticSearch, designed to provide more flexible and Scala-esque interface around the native ElasticSearch Java API.


Add the following to your sbt build:

libraryDependencies += "org.scalastic" %% "scalastic" % ""

Please note, Scalastic supports Scala 2.10.x only.

Way cool, but how do I use it?

In general, look at the test sources for usage examples.

Connect to an ElasticSearch cluster

The main dude is the Indexer:

import scalastic.elasticsearch._

val indexer = Indexer.<some creation method>

Using node-based access:

val indexer = Indexer.local.start
val indexer = Indexer.using(settings) // String or Map
val indexer =

Using a transport client:

val indexer = Indexer.transport(settings = Map(...), host = "...")

General API structure

Just about every Indexer API call has these forms:

indexer.<api-call>          // a blocking call
indexer.<api-call>_send     // async call
indexer.<api-call>_prepare  // get the builder and tailor it all to your heart's content

api-calls employ named parameters and provide default values - you only need to provide what differs.


val indexType = "subnet"

val mapping = s"""
    "$indexType": {
        "properties" : {
            "from" : {"type": "ip"},
            "to" : {"type": "ip"}
val indexName = "networks"

indexer.createIndex(indexName, settings = Map("number_of_shards" -> "1"))

indexer.putMapping(indexName, indexType, mapping)

indexer.index(indexName, indexType, "1", """{"from":"", "to":""}""")

  • for an atomic total-reindexing operation, see indexer.reindexWith method
  • for syncing with indexing operations on a type (index/delete), see the family of methods in the WaitingForGodot trait:
indexer.waitTillCount[AtLeast | Exactly | AtMost]


import org.elasticsearch.index.query.QueryBuilders._ = boolQuery
    .must(rangeQuery("from") lt "")
    .must(rangeQuery("to") gt ""))


import org.elasticsearch.index.query.QueryBuilder

val searchQuery: QueryBuilder = ...
val response = = List("index1", "indexN"),
                              query = searchQuery,
                              from = 100,
                              size = 25 /* and so on */)


Try mixing in the UsingIndexer trait

Building from source

  • Scala 2.10
  • sbt 0.12.3

Versioning scheme

Scalastic versions correspond to ElasticSearch versions (starting from 0.90.0 binaries are available via Maven repo) with a small addition - the fourth component of the version is used to reflect Scalastic improvements/bug fixes.

For example: given ElasticSearch 0.90.0 - Scalastic versions will be 0.90.0,, and so on.



This software is available under Apache 2 license.