Git Product home page Git Product logo

stretchy-pants's Introduction

stretchy pants

o

An elastic wasteband for text

Stretchy pants is a flexible non blocking interface for querying elastic search in scala.

usage

The interface is currently a work in process

doc/indexing

import stretchypants._, dispatch._
import scala.concurrent.ExecutionContext.Implicits.global
import org.json4s.JsonDSL._
import org.json4s.JValue
import org.json4s.native.JsonMethods.{ compact, render }

// initialize client
val es = Client(host)

// initialize an indexer
val tweeter = es.index("twitter", "tweet").doc(_)

// documents are serialized json strings
def str(js: JValue) = compact(render(js))

// create some tweets
tweeter(str(
  ("content" -> "stretchy pants!") ~
  ("user" -> ("name" -> "@stretchy")))).id("1")(as.String).onComplete(println)
tweeter(str(("content" -> "stretchy") ~
  ("user" -> ("name" -> "@pants")))).id("2")(as.String).onComplete(println)
tweeter(str(("content" -> "pants") ~
  ("user" -> ("name" -> "@pantz")))).id("3")(as.String).onComplete(println)
  
  
// get tweets one by one
val tweeting = es.get("twitter", "tweet").id(_)
(1 to 3).foreach(id => tweeting(id.toString)(as.String).onComplete(println))

// get multiple tweets in one swoop
val multiTweeting = es.multiGet.index("twitter").kind("tweet")
multiTweeting.ids((1 to 3).map(_.toString):_*)(as.String).onComplete(println)

// delete tweets one by one
val detweet = es.delete("twitter", "tweet")
(1 to 3).foreach(id => detweet(id.toString)(as.String).onComplete(println))

// or delete tweets by query
val multiDetweet = es.deleteQuery(Query.matchall)
  .index("twitter")
  .kind("tweet")(as.String).onComplete(println)

searching

import stretchypants._, dispatch._
import scala.concurrent.ExecutionContext.Implicits.global

// initialize client
val es = Client(host)

// initialize a search request
val tweets = es.search("twitter", "tweet").query(_)

// query all tweets
tweets(Query.matchall)(as.String).onComplete(println)

// search for the something like stretch in user.name and content fields of a tweet
tweets(Query.fuzzy("stretchy").fields("user.name", "content"))(as.String).onComplete(println)

// search for "stretchy" or "pants" in a field named content
val query = Query.matching(("content", "stretchy pants"))
tweets(query)(as.String).onComplete(println)

// search for "stretchy" and "pants" in a field named content
tweets(query.and)(as.String).onComplete(println)

// search for the phrase "stretchy pants" in a field named content
tweets(query.phrase)(as.String).onComplete(println)

Doug Tangren (softprops) 2014

stretchy-pants's People

Contributors

softprops avatar

Stargazers

Marco F. avatar

Watchers

 avatar James Cloos avatar  avatar

stretchy-pants's Issues

write some tests

travis supports es as a service so it should be straight forward to do so

logo

because I'm clever

gh page based docs

es is like scala, simple on the surface also has a "deeper" side. it may be with writing up more than just a readme for examples and docs

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.