百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

stretcher

> 编程语言
开源

快速、精美、灵活的 ElasticSearch 客户端

356 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

快速、精美、灵活的 ElasticSearch 客户端

Stretcher

This project needs a new maintainer! Please contact @andrewvc if you'd like to take over!

A concise, fast ElasticSearch Ruby client designed to reflect the actual elastic search API as closely as possible. Elastic search's API is complex, and mostly documented on the Elastic Search Guide. This client tries to stay out of your way more than others making advanced techniques easier to implement, and making debugging Elastic Search's sometimes cryptic errors easier. Stretcher is currently in production use by Pose, Get Satisfaction, Reverb, and many others.

Features

  • Cleanly matches up to elastic search's JSON api
  • Efficiently re-uses connections on a per-server object basis (via excon)
  • Supports efficient bulk indexing operations
  • Returns most responses in convenient Hashie::Mash form
  • Configurable logging
  • Logs curl commandline statements in debug mode
  • Pure, threadsafe, ruby
  • Easily swap HTTP clients via Faraday
  • Tested against Ruby 2.0,1.9, Jruby, and Rubinius
  • Semantically versioned

Installation

Add this line to your application's Gemfile:

ruby
gem 'stretcher'

Usage

Getting Started

  1. Basic Usage
  2. Multi Search
  3. Bulk Indexing
  4. Percolate
  5. Logging
  6. Rails Integration

RDocs

Stretcher Strives to provide adequate documentation for all methods. Many methods not described in the 'Getting Started' section can be found in the full rdocs.

  • Stretcher::Server.new.* (Stretcher::Server)
  • Stretcher::Server.new.index(:foo).* (Stretcher::Index)
  • Stretcher::Server.new.index(:foo).type(:bar).* (Stretcher::IndexType)
  • Stretcher::Server.new.index(:foo).search (Stretcher::SearchResult)
  • Stretcher::Server.new.index(:foo).alias(:baz).* (Stretcher::Alias)
  • Stretcher::Server.new.cluster.* (Stretcher::Cluster)

Basic Usage

…

Block Syntax

ruby
# A nested block syntax is also supported.
# with_server takes the same args as #new, but is amenable to blocks
Stretcher::Server.with_server('http://localhost:9200') {|srv|
  srv.index(:foo) {|idx|
    idx.type(:tweet) {|t| {exists: t.exists?, mapping: t.get_mapping} }
  }
}
# => {:exists=>true, :mapping=>#}

Multi Search

ruby
# Within a single index
server.index(:foo).msearch([{query: {match_all: {}}}])
# => Returns an array of Stretcher::SearchResults
# Across multiple indexes
server.msearch([{index: :foo}, {query: {match_all: {}}}])
# => Returns an array of Stretcher::SearchResults

Bulk Indexing

ruby
docs = [{"_type" => "tweet", "_id" => 91011, "text" => "Bulked"}]
server.index(:foo).bulk_index(docs)

Percolate

Implements the ElasticSearch Percolate API

ruby
# Register a new percolate query
server.index(:foo).register_percolator_query(query_name, query_hash)
# Check a document against an index, returns an array of query matches
server.index(:foo).type(:foo1).percolate(doc)
# Delete a percolate query
server.index(:foo).delete_percolator_query(query_name)

Logging

Pass in the :log_level parameter to set logging verbosity. cURL statements are surfaced at the :debug log level. For instance:

ruby
Stretcher::Server.new('http://localhost:9200', :log_level => :debug)

You can also pass any Logger style object with the :logger option. For instance:

ruby
Stretcher::Server.new('http://localhost:9200', :logger => Rails.logger)

Rails Integration

Stretcher is a low level-client, but it was built as a part of a full suite of Rails integration tools. While not yet open-sourced, you can read our detailed blog post: integrating Stretcher with Rails.

Running Specs

Running the specs requires an operational Elastic Search server on http://localhost:9200. The test suite is not to be trusted, don't count on your indexes staying around!

Specs may be run with rake spec

Email or tweet @andrewvc if you'd like to be added to this list!

Contributors

  • @andrewvc
  • @cmaitchison
  • @danharvey
  • @aq1018
  • @akahn
  • @psynix
  • @fmardini
  • @chatgris
  • @alpinegizmo
  • @mcolyer
  • @mulderp

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言