Socket
Book a DemoInstallSign in
Socket

em-stretcher

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

em-stretcher

0.0.2
bundlerRubygems
Version published
Maintainers
1
Created
Source

Em::Stretcher

An EventMachine port of Stretcher (a Fast, Elegant, ElasticSearch client.)

Indexes

Creating an Index

require 'eventmachine'
require "em-stretcher"

EM.run do
  server = EM::Stretcher::Server.new

  server.index('my-index').create
    .callback do |result|
      p result
    end
    .errback do |err|
      p err
    end
end

Deleting an Index

server.index('my-index').delete
	.callback do |result|
	  p result
	end
	.errback do |err|
	  p err
	end

Mappings

Creating a Mapping

mapping = {
  :article => {
    properties: {
      title: { :type => :string }
    }
  }
}

server.index('my-index')
	.type('article')
	.put_mapping(mapping)
	.callback do |result|
		p result
	end
	.errback do |err|
		p err
	end

Indexing Documents

id = 33

server.index('my-index')
  .type(mapping_name)
  .put(id, { title: "My Document with the id #{id}" })
  .callback do |response|
    p response
  end
  .errback do |err|
  	p err
  end

Searching for Documents

server.index('my-index').type('articles')
	.search(size: 50, query: { "query_string" => { "query" => "*" } })
	.documents
	.callback do |r|
		p r
	end

When One Thing Leads to Another

EM::Stretcher uses Deferrable Gratification for chaining together dependent requests.

Here's a great example of when this comes into play:

  • You index several hundred documents in parallel.
  • You want to perform a search on the index, with all the documents present.

Here's how you can pull this off with Deferrable Gratification:

# Index some documents in parallel.
(0..50).each do |i|
	server.index('my-index')
	  .type('articles')
	  .put(i, { title: "title #{i}" })
	  .callback do |response|
	    p response
	  end
end

# First we wait for the indexing to finish.
server.index('my-index').refresh
	.bind! do

	  # Then we perform the search.
	  server.index('my-index').type('articles')
	    .search(size: 50, query: { "query_string" => { "query" => "*" } })
	    .documents
	    .callback do |r|
	      p r # all 50 results should have been returned.
	    end
	end

Installation

Add this line to your application's Gemfile:

gem 'em-stretcher'

And then execute:

$ bundle

Or install it yourself as:

$ gem install em-stretcher

Contributing

  • Fork it ( http://github.com/bcoe/em-stretcher/fork )
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

FAQs

Package last updated on 11 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.