Code Monkey home page Code Monkey logo

elastic-feeder's Introduction

ElasticFeeder

Build Status

What does it do?

ElasticFeeder is a very small library that helps you to get data into ElasticSearch quickly. It is written in Scala, but it may work for Java, too.

How does it work?

Add ElasticFeeder to your build.sbt:

libraryDependencies += "com.spruenker" %% "elastic-feeder" % "1.1.0"

Create a new elastic-feeder object:

val feeder = new ElasticFeeder(_index = "my-index")

This will generate give you a feeder that tries to use an ElasticSearch server on localhost:9300. If you want to use another server:

val feeder = new ElasticFeeder("example.org", 9123, "my-index")

Now you have to give the feeder some data. You can feed it with Sequences (e.g. List) of objects, that implement the IdDocumentMap trait, which is really simple. It needs implementations of two methods:

/** Simplified. **/
trait IdDocumentMap {
  def _id: String
  def map: Map[String, Any]
}

The result of the _id-function will be used as the id of the document in ElasticSearch. The map-function just maps all the properties of your model to the properties you want in your ElasticSearch document. Here is an example:

case class Order(contractNumber: Long, eventDate: Date, clerkId: String, brandId: Integer, signed: String, url: String) extends IdDocumentMap {

  override def _id: String = contractNumber.toString

  override def map: Map[String, Any] = {
    Map(
    "contractNumber" -> contractNumber,
    "eventDate" -> eventDate,
    "clerkId" -> clerkId,
    "brandId" -> brandId,
    "signed" -> { if (signed.equals("N")) false else true },
    "url" -> url
    )
  }
}

As you can see, you can even transform properties from your case class to something you want in your ElasticSearch document.

Let's save some Orders into ElasticSearch:

val orders: List[Order] = getOrders
feeder.put(orders)

That's it. ElasticFeeder will take your list of Orders and feed it to ElasticSearch. It uses one or more bulk operations to do that to keep things fast.

Developers

ElasticFeeder is written in Scala and built with sbt:

sbt compile

elastic-feeder's People

Contributors

srsp avatar

Watchers

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