# Scalastic: scala driver for elasticsearch

**URL:** <https://discuss.elastic.co/t/scalastic-scala-driver-for-elasticsearch/7303>\
**Category:** Elasticsearch\
**Created:** [April 12, 2012, 7:27am UTC](https://discuss.elastic.co/t/scalastic-scala-driver-for-elasticsearch/7303 "2012-04-12T07:27:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![benny\_sadeh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benny_sadeh/32/2797_2.png) [@benny\_sadeh](https://discuss.elastic.co/u/benny_sadeh)\
**Post date:** [April 12, 2012, 7:27am UTC](https://discuss.elastic.co/t/scalastic-scala-driver-for-elasticsearch/7303/1 "2012-04-12T07:27:48Z")

</div>

for the scalatistas among us, check out  
scalastic[https://github.com/bsadeh/scalastic](https://github.com/bsadeh/scalastic)

- a Scala driver for ElasticSearch [http://www.elasticsearch.org/](http://www.elasticsearch.org/)  
please take it for a spin, and if you have needs the driver does not  
provide, do let me know.

also, what is the process (or magic incantation) I need to follow to add it  
to the Clients &  
Integrations[http://www.elasticsearch.org/guide/appendix/clients.html](http://www.elasticsearch.org/guide/appendix/clients.html)  
page?

best,  
Benny

from the README:About

Scalastic is an interface for ElasticSearch [http://www.elasticsearch.org/](http://www.elasticsearch.org/),  
designed to provide more flexible and Scala-esque interface around the  
nativeelasticsearch Java  
API[http://www.elasticsearch.org/guide/reference/java-api/](http://www.elasticsearch.org/guide/reference/java-api/)  
.

Scalastic has been developed and tested against elasticsearch 1.9.x+.  
Way cool, but how do I use it?

in general, look at the scalatest source for usage examples ...

the main dude is the Indexer: import com.traackr.elasticsearch.\_ val  
indexer = Indexer.

just about every Indexer api call has these forms: indexer. // a blocking  
call indexer.send\* // async call indexer.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.  
Creating an Indexer (connecting to an elastic cluster)

using node-based access:

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

using a transport client: val indexer = Indexer.transport(settings =  
Map(...), host = "...")  
Indexing

val mapping = """  
{  
"type1": {  
"properties" : {  
"from" : {"type": "ip"},  
"to" : {"type": "ip"}  
}  
}  
}  
"""  
indexer.createIndex("index1", settings = """{"number\_of\_shards":1}""")  
indexer.waitTillActive()  
indexer.putMapping(indexName, "type9", mapping)  
indexer.index(indexName, "type9", "1", """{"from":"192.168.0.5",  
"to":"192.168.0.10"}""")  
indexer.refresh()

Searching

indexer.search(query = boolQuery  
.must(rangeQuery("from") lt "192.168.0.7")  
.must(rangeQuery("to") gt "192.168.0.7"))

or: val response = indexer.search(indices=List(index1, indexN), query =  
some\_narly\_query, from=100, size=25, etc. etc.)  
Testing

- try mixing in the UsingIndexer trait

Building

- sbt 0.11.2
- Maven 3.0.4

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 12, 2012, 7:31am UTC](https://discuss.elastic.co/t/scalastic-scala-driver-for-elasticsearch/7303/2 "2012-04-12T07:31:11Z")

</div>

Create a pull request in github on the [elasticsearch.github.com](http://elasticsearch.github.com) project to add it as a Client.

David 😉  
Twitter : @dadoonet / @elasticsearchfr

Le 12 avr. 2012 à 09:27, Benny Sadeh [benny.sadeh@gmail.com](mailto:benny.sadeh@gmail.com) a écrit :

> for the scalatistas among us, check out scalastic - a Scala driver for Elasticsearch  
> please take it for a spin, and if you have needs the driver does not provide, do let me know.
> 
> also, what is the process (or magic incantation) I need to follow to add it to the Clients & Integrations page?
> 
> best,  
> Benny
> 
> from the README:
> 
> About
> 
> Scalastic is an interface for Elasticsearch, designed to provide more flexible and Scala-esque interface around the nativeelasticsearch Java API.
> 
> Scalastic has been developed and tested against elasticsearch 1.9.x+.
> 
> Way cool, but how do I use it?
> 
> in general, look at the scalatest source for usage examples ...
> 
> the main dude is the Indexer: import com.traackr.elasticsearch.\_ val indexer = Indexer.
> 
> just about every Indexer api call has these forms: indexer. // a blocking call indexer.send // async call indexer.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.
> 
> Creating an Indexer (connecting to an elastic cluster)
> 
> using node-based access:
> 
> val indexer = Indexer.local.start  
> val indexer = Indexer.using(settings) // String or Map  
> val indexer = Indexer.at(node)  
> using a transport client: val indexer = Indexer.transport(settings = Map(...), host = "...")
> 
> Indexing
> 
> val mapping = """  
> {  
> "type1": {  
> "properties" : {  
> "from" : {"type": "ip"},  
> "to" : {"type": "ip"}  
> }  
> }  
> }  
> """  
> indexer.createIndex("index1", settings = """{"number\_of\_shards":1}""")  
> indexer.waitTillActive()  
> indexer.putMapping(indexName, "type9", mapping)  
> indexer.index(indexName, "type9", "1", """{"from":"192.168.0.5", "to":"192.168.0.10"}""")  
> indexer.refresh()  
> Searching
> 
> indexer.search(query = boolQuery  
> .must(rangeQuery("from") lt "192.168.0.7")  
> .must(rangeQuery("to") gt "192.168.0.7"))  
> or: val response = indexer.search(indices=List(index1, indexN), query = some\_narly\_query, from=100, size=25, etc. etc.)
> 
> Testing
> 
> try mixing in the UsingIndexer trait  
> Building
> 
> sbt 0.11.2  
> Maven 3.0.4

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:32am UTC](https://discuss.elastic.co/t/scalastic-scala-driver-for-elasticsearch/7303/3 "2017-07-06T03:32:52Z")

</div>


