The Wayback Machine - https://web.archive.org/web/20190322190825/https://github.com/github/elastomer-client
Skip to content
Please note that GitHub no longer supports Internet Explorer.

We recommend upgrading to the latest Microsoft Edge, Google Chrome, or Firefox.

Learn more
A library for interacting with Elasticsearch
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docker
docs [breaking] rename `Index#optimize` to `Index#forcemerge` Nov 30, 2017
lib/elastomer
script adding some comments Jan 11, 2018
test
.gitignore
.overcommit.yml Set the RuboCop output format to emacs Sep 23, 2015
.rubocop.yml Disable all cops by default Sep 23, 2015
.travis.yml Remove allowed failures from ES 5.X Travis CI builds Dec 7, 2017
CHANGELOG.md
Gemfile Fix RuboCop Style/StringLiterals offenses Sep 23, 2015
LICENSE.txt
README.md
Rakefile
elastomer-client.gemspec Request compressed responses from Elasticsearch Jun 8, 2018

README.md

Elastomer Client Build Status

Making a stupid simple Elasticsearch client so your project can be smarter!

Getting Started

Get started by cloning and running a few scripts:

$ git clone https://github.com/github/elastomer-client.git
$ cd elastomer-client
$ script/bootstrap
$ rake test

Client

The client provides a one-to-one mapping to the Elasticsearch API endpoints. The API is decomposed into logical sections and accessed according to what you are trying to accomplish. Each logical section is represented as a client class and a top-level accessor is provided for each.

Cluster

API endpoints dealing with cluster level information and settings are found in the Cluster class.

require 'elastomer/client'
client = Elastomer::Client.new

# the current health summary
client.cluster.health

# detailed cluster state information
client.cluster.state

# the list of all index templates
client.cluster.templates

Index

The methods in the Index class deal with the management of indexes in the cluster. This includes setting up type mappings and adjusting settings. The actual indexing and search of documents are handled by the Docs class (discussed next).

require 'elastomer/client'
client = Elastomer::Client.new

index = client.index('twitter')
index.create(
  :settings => { 'index.number_of_shards' => 3 },
  :mappings => {
    :tweet => {
      :_source => { :enabled => true },
      :_all    => { :enabled => false },
      :properties => {
        :author => { :type => 'string', :index => 'not_analyzed' },
        :tweet  => { :type => 'string', :analyze => 'standard' }
      }
    }
  }
)

index.exists?

index.exists? :type => 'tweet'

index.delete

Docs

The Docs class handles the indexing and searching of documents. Each instance is scoped to an index and optionally a document type.

require 'elastomer/client'
client = Elastomer::Client.new

docs = client.docs('twitter')

docs.index({
  :_id    => 1,
  :_type  => 'tweet',
  :author => '@pea53',
  :tweet  => 'announcing Elastomer, the stupid simple Elasticsearch client'
})

docs.search({:query => {:match_all => {}}}, :size => 0)

Performance

By default Elastomer uses Net::HTTP (via Faraday) to communicate with Elasticsearch. You may find that Excon performs better for your use. To enable Excon, add it to your bundle and then change your Elastomer initialization thusly:

Elastomer::Client.new(url: YOUR_ES_URL, adapter: :excon)
You can’t perform that action at this time.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.