Need help with scalastic?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

bsadeh
121 Stars 35 Forks Other 177 Commits 2 Opened issues

Description

scala driver for elasticsearch

Services available

!
?

Need anything else?

Contributors list

# 443,730
Scala
94 commits
# 145,256
logback
logstas...
Shell
PHP
14 commits
# 72,414
Ruby
chef-co...
chef-re...
Shell
12 commits
# 199,998
PHP
twig-ex...
Scala
playfra...
11 commits
# 237,107
Apache ...
wikiped...
asgi
SQL
6 commits
# 433,189
Scala
sbt
Emacs
languag...
3 commits
# 578,315
Scala
Java
3 commits
# 670,624
Scala
2 commits
# 15,101
Objecti...
prose
React
re-fram...
1 commit

Scalastic

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.

Installation

Add the following to your sbt build:

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

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.

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 = "...")

General API structure

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-call
s employ named parameters and provide default values - you only need to provide what differs.

Indexing

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.waitTillActive()

indexer.putMapping(indexName, indexType, mapping)

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

indexer.refresh()

  • 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]

Searching

import org.elasticsearch.index.query.QueryBuilders._

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

or:

import org.elasticsearch.index.query.QueryBuilder

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

Testing

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, 0.90.0.1, 0.90.0.2 and so on.

Contributors

License

This software is available under Apache 2 license.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.