Scala driver for ElasticSearch
- Benny Sadeh [email protected]
- you?
Scalastic is an interface for ElasticSearch, designed to provide more flexible and Scala-esque interface around the native elasticsearch Java API.
Scalastic has been developed and tested against elasticsearch 1.9.x+.
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.
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 = "...")
val mapping = """
{
"type1": {
"properties" : {
"from" : {"type": "ip"},
"to" : {"type": "ip"}
}
}
}
"""
indexer.createIndex("index1", settings = """{"number_of_shards":1}""")
indexer.waitTillActive()
indexer.putMapping(indexName, "type1", mapping)
indexer.index(indexName, "type1", "1", """{"from":"192.168.0.5", "to":"192.168.0.10"}""")
indexer.refresh()
-
for an atomic total-reindexing operation, see:
indexer.reindexWith
-
for syncing with indexing operations on a type (index/delete), see the family of methods in the WaitingForGodot trait:
indexer.waitTillCount[AtLeast | Exactly | AtMost]
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.)
- try mixing in the UsingIndexer trait
- sbt 0.11.2
- Maven 3.0.4