Skip to content

Latest commit

 

History

History
executable file
·
83 lines (60 loc) · 2.3 KB

README.md

File metadata and controls

executable file
·
83 lines (60 loc) · 2.3 KB

Scalastic

Scala driver for ElasticSearch

Contributors

About

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+.

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, "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]

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