stretcher 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +23 -10
- data/lib/stretcher/index.rb +10 -1
- data/lib/stretcher/index_type.rb +2 -1
- data/lib/stretcher/search_results.rb +8 -0
- data/lib/stretcher/server.rb +6 -2
- data/lib/stretcher/version.rb +1 -1
- data/stretcher.gemspec +1 -0
- metadata +17 -1
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Stretcher
|
2
2
|
|
3
|
-
A concise, fast
|
3
|
+
A concise, fast ElasticSearch 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.
|
4
4
|
|
5
5
|
# Features
|
6
6
|
|
@@ -8,14 +8,16 @@ A concise, fast, ElasticSearch client designed to reflect the actual elastic se
|
|
8
8
|
* Efficiently re-uses connections on a per-server object basis (via net/http/persistent)
|
9
9
|
* Supports efficient bulk indexing operations
|
10
10
|
* Returns most responses in convenient Hashie::Mash form
|
11
|
-
* Easily extensible
|
12
11
|
* Configurable logging
|
12
|
+
* Pure, threadsafe, ruby
|
13
13
|
|
14
14
|
## Installation
|
15
15
|
|
16
16
|
Add this line to your application's Gemfile:
|
17
17
|
|
18
|
-
|
18
|
+
```ruby
|
19
|
+
gem 'stretcher'
|
20
|
+
```
|
19
21
|
|
20
22
|
## Usage
|
21
23
|
|
@@ -25,15 +27,15 @@ Add this line to your application's Gemfile:
|
|
25
27
|
# First Create a server
|
26
28
|
server = Stretcher::Server.new('http://localhost:9200')
|
27
29
|
# Delete an index (in case you already have this one)
|
28
|
-
server.index(
|
30
|
+
server.index(:foo).delete rescue nil
|
29
31
|
# Create an index
|
30
|
-
server.index(
|
32
|
+
server.index(:foo).create(mapping: {tweet: {properties: {text: 'string'}}})
|
31
33
|
# Add a document
|
32
|
-
server.index(
|
34
|
+
server.index(:foo).type(:tweet).put(123, {text: 'Hello'})
|
33
35
|
# Retrieve a document
|
34
|
-
server.index(
|
36
|
+
server.index(:foo).type(:tweet).get(123)
|
35
37
|
# Perform a search (Returns a Stretcher::SearchResults instance)
|
36
|
-
res = server.index(
|
38
|
+
res = server.index(:foo).search({size: 12}, {query: {match_all: {}}})
|
37
39
|
res.class # Stretcher::SearchResults
|
38
40
|
res.total # => 1
|
39
41
|
res.facets # => nil
|
@@ -41,7 +43,7 @@ res.results # => [#<Hashie::Mash _id="123" text="Hello">]
|
|
41
43
|
res.raw # => #<Hashie::Mash ...> Raw JSON from the search
|
42
44
|
```
|
43
45
|
|
44
|
-
###
|
46
|
+
### Multi Search
|
45
47
|
|
46
48
|
```ruby
|
47
49
|
server.index('foo').msearch([{query: {match_all: {}}}])
|
@@ -52,9 +54,20 @@ server.index('foo').msearch([{query: {match_all: {}}}])
|
|
52
54
|
|
53
55
|
```ruby
|
54
56
|
docs = [{"_type" => "tweet", "_id" => 91011, "text" => "Bulked"}]
|
55
|
-
server.index(
|
57
|
+
server.index(:foo).bulk_index(docs)
|
56
58
|
```
|
57
59
|
|
60
|
+
### Full Documentation
|
61
|
+
|
62
|
+
This README documents only part of stretcher's API. The full documentation for stretcher is available in its [full rdocs](http://rdoc.info/github/PoseBiz/stretcher/master/frames).
|
63
|
+
|
64
|
+
## Running Specs
|
65
|
+
|
66
|
+
Running the specs requires an operational Elastic Search server on http://localhost:9200.
|
67
|
+
The test suite is not to be trusted, don't count on your indexes staying around!
|
68
|
+
|
69
|
+
Specs may be run with `rake spec`
|
70
|
+
|
58
71
|
## Contributing
|
59
72
|
|
60
73
|
1. Fork it
|
data/lib/stretcher/index.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'stretcher/search_results'
|
2
2
|
module Stretcher
|
3
|
+
# Represents an Index context in elastic search.
|
4
|
+
# Generally should be instantiated via Server#index(name).
|
3
5
|
class Index
|
4
6
|
attr_reader :server, :name, :logger
|
5
7
|
|
@@ -55,7 +57,14 @@ module Stretcher
|
|
55
57
|
def exists?
|
56
58
|
@server.http.head(path_uri).status != 404
|
57
59
|
end
|
58
|
-
|
60
|
+
|
61
|
+
# Issues a search with the given query opts and body, both should be hashes
|
62
|
+
# Ex: res = server.index('foo').search({size: 12}, {query: {match_all: {}}})
|
63
|
+
# * es.class # Stretcher::SearchResults
|
64
|
+
# * res.total # => 1
|
65
|
+
# * res.facets # => nil
|
66
|
+
# * res.results # => [#<Hashie::Mash _id="123" text="Hello">]
|
67
|
+
# * res.raw # => #<Hashie::Mash ...> Raw JSON from the search
|
59
68
|
def search(query_opts={}, body=nil)
|
60
69
|
uri = path_uri('/_search?' + Util.querify(query_opts))
|
61
70
|
logger.info { "Stretcher Search: curl -XGET #{uri} -d '#{body.to_json}'" }
|
data/lib/stretcher/index_type.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
require 'hashie/dash'
|
2
2
|
module Stretcher
|
3
|
+
# Conveniently represents elastic search results in a more compact fashion
|
4
|
+
#
|
5
|
+
# Available properties:
|
6
|
+
#
|
7
|
+
# * raw : The raw response from elastic search
|
8
|
+
# * total : The total number of matched docs
|
9
|
+
# * facets : the facets hash
|
10
|
+
# * results : The hit results with _id merged in to _source
|
3
11
|
class SearchResults < Hashie::Dash
|
4
12
|
property :raw, required: true
|
5
13
|
property :total
|
data/lib/stretcher/server.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
module Stretcher
|
2
2
|
class Server
|
3
3
|
attr_reader :uri, :http, :logger
|
4
|
-
|
4
|
+
|
5
|
+
# Represents a Server context in elastic search.
|
6
|
+
# The options hash takes an optional instance of Logger under :logger.
|
7
|
+
#
|
8
|
+
# Ex: server = Stretcher::Server.new('http://localhost:9200').
|
5
9
|
def initialize(uri, options={})
|
6
10
|
@uri = uri
|
7
11
|
|
@@ -81,7 +85,7 @@ module Stretcher
|
|
81
85
|
# Handy way to query the server, returning *only* the body
|
82
86
|
# Will raise an exception when the status is not in the 2xx range
|
83
87
|
def request(method, *args, &block)
|
84
|
-
logger.info
|
88
|
+
logger.info { "Stretcher: Issuing Request #{method.upcase}, #{args}" }
|
85
89
|
res = if block
|
86
90
|
http.send(method, *args) do |req|
|
87
91
|
# Elastic search does mostly deal with JSON
|
data/lib/stretcher/version.rb
CHANGED
data/stretcher.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stretcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -107,6 +107,22 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: vcr
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
110
126
|
- !ruby/object:Gem::Dependency
|
111
127
|
name: rake
|
112
128
|
requirement: !ruby/object:Gem::Requirement
|