GithubHelp home page GithubHelp logo

scalastic's Introduction

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.<some creation method>

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

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.

scalastic's People

Contributors

bsadeh avatar yatskevich avatar martinb3 avatar cldellow avatar charith-qubit avatar stevesie88 avatar stig avatar

Watchers

edwardt avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.