stretcher 1.19.0 → 1.20.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -4
- data/README.md +29 -11
- data/lib/stretcher.rb +2 -0
- data/lib/stretcher/alias.rb +63 -0
- data/lib/stretcher/cluster.rb +26 -0
- data/lib/stretcher/es_component.rb +1 -1
- data/lib/stretcher/index.rb +13 -2
- data/lib/stretcher/search_results.rb +74 -15
- data/lib/stretcher/server.rb +10 -2
- data/lib/stretcher/version.rb +1 -1
- data/spec/lib/stretcher_alias_spec.rb +50 -0
- data/spec/lib/stretcher_cluster_spec.rb +17 -0
- data/spec/lib/stretcher_index_spec.rb +6 -18
- data/spec/lib/stretcher_index_type_spec.rb +3 -4
- data/spec/lib/stretcher_search_results_spec.rb +15 -14
- data/spec/spec_helper.rb +19 -0
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b5b15a976457a848c084d824c8cb40274ff0ee4
|
4
|
+
data.tar.gz: 9493a22fb07da4788c7a011a7f6bacbc4f7d8a57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e31a69397b930852118068f572bed8f5dfdada0e0b9a8f41b5bbd246f593a350b4b92585ac293d86c3933b09be784922b7491b9f0d4c72fd01c4442cc39b7bd3
|
7
|
+
data.tar.gz: 373a51fd9cbf6859f6925007b2c313f5ae099755dd91edd5f38a17c78542893bdd0f96a5ce57d63b66de67fea2c253a8f0b663b19295d5daa8f9a96940306ee8
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
[![Code Climate](https://codeclimate.com/github/PoseBiz/stretcher.png)](https://codeclimate.com/github/PoseBiz/stretcher)
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/PoseBiz/stretcher/badge.png)](https://coveralls.io/r/PoseBiz/stretcher)
|
7
7
|
|
8
|
-
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.
|
8
|
+
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.
|
9
9
|
|
10
10
|
# Features
|
11
11
|
|
@@ -18,6 +18,7 @@ A concise, fast ElasticSearch client designed to reflect the actual elastic sear
|
|
18
18
|
* Pure, threadsafe, ruby
|
19
19
|
* Easily swap HTTP clients via Faraday
|
20
20
|
* Tested against Ruby 2.0,1.9,1.8.7, Jruby, and Rubinius
|
21
|
+
* [Semantically versioned](http://semver.org/)
|
21
22
|
|
22
23
|
## Installation
|
23
24
|
|
@@ -29,6 +30,26 @@ gem 'stretcher'
|
|
29
30
|
|
30
31
|
## Usage
|
31
32
|
|
33
|
+
#### Getting Started
|
34
|
+
|
35
|
+
1. [Basic Usage](https://github.com/PoseBiz/stretcher#basic-usage)
|
36
|
+
1. [Multi Search](https://github.com/PoseBiz/stretcher#multi-search)
|
37
|
+
1. [Bulk Indexing](https://github.com/PoseBiz/stretcher#bulk-indexing)
|
38
|
+
1. [Percolate](https://github.com/PoseBiz/stretcher#percolate)
|
39
|
+
1. [Logging](https://github.com/PoseBiz/stretcher#logging)
|
40
|
+
1. [Rails Integration](https://github.com/PoseBiz/stretcher#rails-integration)
|
41
|
+
|
42
|
+
#### RDocs
|
43
|
+
|
44
|
+
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](http://rdoc.info/github/PoseBiz/stretcher/master/frames).
|
45
|
+
|
46
|
+
* [Stretcher::Server.new.* (Stretcher::Server)](http://rdoc.info/github/PoseBiz/stretcher/master/Stretcher/Server)
|
47
|
+
* [Stretcher::Server.new.index(:foo).* (Stretcher::Index)](http://rdoc.info/github/PoseBiz/stretcher/master/Stretcher/Index)
|
48
|
+
* [Stretcher::Server.new.index(:foo).type(:bar).* (Stretcher::IndexType)](http://rdoc.info/github/PoseBiz/stretcher/master/Stretcher/IndexType)
|
49
|
+
* [Stretcher::Server.new.index(:foo).search (Stretcher::SearchResult)](http://rdoc.info/github/PoseBiz/stretcher/master/Stretcher/SearchResult)
|
50
|
+
* [Stretcher::Server.new.index(:foo).alias(:baz).* (Stretcher::Alias)](http://rdoc.info/github/PoseBiz/stretcher/master/Stretcher/Alias)
|
51
|
+
* [Stretcher::Server.new.cluster.* (Stretcher::Cluster)](http://rdoc.info/github/PoseBiz/stretcher/master/Stretcher/Cluster)
|
52
|
+
|
32
53
|
### Basic Usage
|
33
54
|
|
34
55
|
```ruby
|
@@ -47,9 +68,15 @@ server.index(:foo).type(:tweet).get(3)
|
|
47
68
|
res = server.index(:foo).search(size: 12, query: {match_all: {}})
|
48
69
|
res.class # Stretcher::SearchResults
|
49
70
|
res.total # => 30
|
50
|
-
res.
|
71
|
+
res.documents # => [#<Hashie::Mash _id="4" text="Hello 4">, ...]
|
51
72
|
res.facets # => nil
|
52
73
|
res.raw # => #<Hashie::Mash ...> Raw JSON from the search
|
74
|
+
# use an alias
|
75
|
+
alias = server.index(:foo).alias(:my_alias)
|
76
|
+
alias.create({ filter: { term: { user_id: 1 } } })
|
77
|
+
alias.index_context.search({ query: { match_all: {} } })
|
78
|
+
# or get some cluster health information
|
79
|
+
server.cluster.health # Hashie::Mash
|
53
80
|
```
|
54
81
|
|
55
82
|
### Block Syntax
|
@@ -96,10 +123,6 @@ server.index(:foo).type(:foo1).percolate(doc)
|
|
96
123
|
server.index(:foo).delete_percolator_query(query_name)
|
97
124
|
```
|
98
125
|
|
99
|
-
### Full Documentation
|
100
|
-
|
101
|
-
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).
|
102
|
-
|
103
126
|
### Logging
|
104
127
|
|
105
128
|
Pass in the `:log_level` parameter to set logging verbosity. cURL statements are surfaced at the `:debug` log level. For instance:
|
@@ -126,11 +149,6 @@ The test suite is not to be trusted, don't count on your indexes staying around!
|
|
126
149
|
|
127
150
|
Specs may be run with `rake spec`
|
128
151
|
|
129
|
-
## Used By
|
130
|
-
|
131
|
-
* [Pose](http://pose.com)
|
132
|
-
* [Get Satisfaction](https://getsatisfaction.com/corp/)
|
133
|
-
|
134
152
|
Email or tweet @andrewvc if you'd like to be added to this list!
|
135
153
|
|
136
154
|
## Contributors
|
data/lib/stretcher.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Stretcher
|
2
|
+
|
3
|
+
# Represents an Alias in elastic search.
|
4
|
+
# Generally should be used via Index#alias(name)
|
5
|
+
class Alias < EsComponent
|
6
|
+
|
7
|
+
attr_reader :name
|
8
|
+
|
9
|
+
def initialize(index, name, options = {})
|
10
|
+
@index = index
|
11
|
+
@server = index.server
|
12
|
+
@name = name
|
13
|
+
@logger = options[:logger] || server.logger
|
14
|
+
end
|
15
|
+
|
16
|
+
# Get the index context of this alias (use it as if it was the index
|
17
|
+
# which it represents)
|
18
|
+
#
|
19
|
+
# my_alias.index_context.search({ query: { match_all: {} } })
|
20
|
+
def index_context
|
21
|
+
@server.index(@name)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Create the alias in elastic search with the given options
|
25
|
+
#
|
26
|
+
# my_alias.create({ filter: { term: { user_id: 1 } } })
|
27
|
+
def create(options = {})
|
28
|
+
request(:put) do |req|
|
29
|
+
req.body = {
|
30
|
+
actions: [
|
31
|
+
add: options.merge(:alias => @name)
|
32
|
+
]
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Delete an alias from elastic search
|
38
|
+
#
|
39
|
+
# my_alias.delete
|
40
|
+
def delete
|
41
|
+
request(:delete)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Determine whether an alias by this name exists
|
45
|
+
#
|
46
|
+
# my_alias.exist? # true
|
47
|
+
def exist?
|
48
|
+
request(:get)
|
49
|
+
true
|
50
|
+
rescue Stretcher::RequestError::NotFound
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
# Full path to this alias
|
57
|
+
def path_uri(path = nil)
|
58
|
+
p = @index.path_uri("_alias/#{@name}")
|
59
|
+
path ? p << "/#{path}" : p
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Stretcher
|
2
|
+
|
3
|
+
# Represents a cluster of servers
|
4
|
+
# should be reached typically through Server#cluster
|
5
|
+
class Cluster < EsComponent
|
6
|
+
|
7
|
+
def initialize(server, options = {})
|
8
|
+
@server = server
|
9
|
+
@logger = options[:logger] || server.logger
|
10
|
+
end
|
11
|
+
|
12
|
+
# Get the health of the cluster
|
13
|
+
def health(options = {})
|
14
|
+
request(:get, 'health', options)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def path_uri(path = nil)
|
20
|
+
p = @server.path_uri('/_cluster')
|
21
|
+
path ? "#{p}/#{path}" : p
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/lib/stretcher/index.rb
CHANGED
@@ -22,6 +22,17 @@ module Stretcher
|
|
22
22
|
block ? block.call(t) : t
|
23
23
|
end
|
24
24
|
|
25
|
+
# Returns a Stretcher::Alias object for the alias +name+.
|
26
|
+
# Optionally takes a block, which will be passed a single arg with the Alias obj
|
27
|
+
# The block syntax returns the evaluated value of the block
|
28
|
+
#
|
29
|
+
# my_server.alias('user_1') # Stretcher::Alias
|
30
|
+
# my_server.alias { |alias| 1 } # 1
|
31
|
+
def alias(name, &block)
|
32
|
+
al = Alias.new(self, name, :logger => logger)
|
33
|
+
block ? block.call(al) : al
|
34
|
+
end
|
35
|
+
|
25
36
|
# Given a hash of documents, will bulk index
|
26
37
|
#
|
27
38
|
# docs = [{"_type" => "tweet", "_id" => 91011, "text" => "Bulked"}]
|
@@ -50,8 +61,8 @@ module Stretcher
|
|
50
61
|
index_meta[key] = d.delete(key) if system_fields.include?(key.to_s)
|
51
62
|
end
|
52
63
|
|
53
|
-
post_data << (MultiJson.dump({action => index_meta})
|
54
|
-
post_data << (MultiJson.dump(d)
|
64
|
+
post_data << (MultiJson.dump({action => index_meta}) << "\n")
|
65
|
+
post_data << (MultiJson.dump(d) << "\n") unless action == :delete
|
55
66
|
post_data
|
56
67
|
}
|
57
68
|
@server.bulk body, options
|
@@ -8,24 +8,83 @@ module Stretcher
|
|
8
8
|
# * total : The total number of matched docs
|
9
9
|
# * facets : the facets hash
|
10
10
|
# * results : The hit results with _id merged in to _source
|
11
|
-
class SearchResults
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
class SearchResults
|
12
|
+
def initialize(raw)
|
13
|
+
@raw_plain = raw
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns a plain (string keyed) hash of the raw response
|
17
|
+
def raw_plain
|
18
|
+
@raw_plain
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns a Hashie::Mash version of the raw response
|
22
|
+
def raw
|
23
|
+
@raw ||= Hashie::Mash.new(@raw_plain)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the total number of results
|
27
|
+
def total
|
28
|
+
@total ||= raw_plain['hits']['total']
|
29
|
+
end
|
30
|
+
|
31
|
+
def facets
|
32
|
+
@facets ||= raw[:facets]
|
33
|
+
end
|
34
|
+
|
35
|
+
# DEPRECATED!
|
36
|
+
# Call #documents instead!
|
37
|
+
def results
|
38
|
+
pretty
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns a 'prettier' version of elasticsearch results
|
42
|
+
# This will:
|
43
|
+
#
|
44
|
+
# 1. Return either '_source' or 'fields' as the base of the result
|
45
|
+
# 2. Merge any keys beginning with a '_' into it as well (such as '_score')
|
46
|
+
# 3. Copy the 'highlight' field into '_highlight'
|
47
|
+
#
|
48
|
+
def pretty
|
49
|
+
# This function and its helpers are side-effecty for speed
|
50
|
+
@documents ||= raw[:hits][:hits].map do |hit|
|
51
|
+
doc = extract_source(hit)
|
52
|
+
copy_underscores(hit, doc)
|
53
|
+
copy_highlight(hit, doc)
|
54
|
+
doc
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def extract_source(hit)
|
61
|
+
# Memoize the key, since it will be uniform across results
|
62
|
+
@doc_key ||= if hit.key?(:_source)
|
63
|
+
:_source
|
64
|
+
elsif hit.key?(:fields)
|
65
|
+
:fields
|
66
|
+
else
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
Hashie::Mash.new(@doc_key ? hit[@doc_key] : Hashie::Mash.new)
|
71
|
+
end
|
16
72
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
k = ['_source', 'fields'].detect { |k| r.key?(k) }
|
23
|
-
doc = k.nil? ? Hashie::Mash.new : r[k]
|
24
|
-
if r.key?('highlight')
|
25
|
-
doc.merge!({"_highlight" => r['highlight']})
|
73
|
+
def copy_underscores(hit, doc)
|
74
|
+
# Copy underscore keys into the document
|
75
|
+
hit.each do |k,v|
|
76
|
+
if k && k[0] == "_"
|
77
|
+
doc[k] = v
|
26
78
|
end
|
27
|
-
doc.merge!({"_id" => r['_id'], "_index" => r['_index'], "_type" => r['_type'], "_score" => r['_score']})
|
28
79
|
end
|
80
|
+
doc
|
81
|
+
end
|
82
|
+
|
83
|
+
def copy_highlight(hit, doc)
|
84
|
+
if highlight = hit.key?("highlight")
|
85
|
+
doc[:_highlight] = highlight
|
86
|
+
end
|
87
|
+
doc
|
29
88
|
end
|
30
89
|
end
|
31
90
|
end
|
data/lib/stretcher/server.rb
CHANGED
@@ -95,6 +95,14 @@ module Stretcher
|
|
95
95
|
block ? block.call(idx) : idx
|
96
96
|
end
|
97
97
|
|
98
|
+
# Returns the Stretcher::Cluster for this server
|
99
|
+
# Optionally takes a block, which will be passed a single arg with the
|
100
|
+
# Cluster object. The block returns the evaluated value of the block.
|
101
|
+
def cluster(&block)
|
102
|
+
cluster = Cluster.new(self, :logger => logger)
|
103
|
+
block ? block.call(cluster) : cluster
|
104
|
+
end
|
105
|
+
|
98
106
|
# Perform a raw bulk operation. You probably want to use Stretcher::Index#bulk_index
|
99
107
|
# which properly formats a bulk index request.
|
100
108
|
def bulk(data, options={})
|
@@ -129,7 +137,7 @@ module Stretcher
|
|
129
137
|
# server.msearch(data)
|
130
138
|
def msearch(body=[])
|
131
139
|
raise ArgumentError, "msearch takes an array!" unless body.is_a?(Array)
|
132
|
-
fmt_body = body.map {|l| MultiJson.dump(l) }.join("\n")
|
140
|
+
fmt_body = body.map {|l| MultiJson.dump(l) }.join("\n") << "\n"
|
133
141
|
|
134
142
|
res = request(:get, path_uri("/_msearch"), {}, fmt_body)
|
135
143
|
|
@@ -138,7 +146,7 @@ module Stretcher
|
|
138
146
|
raise RequestError.new(res), "Could not msearch #{errors.inspect}"
|
139
147
|
end
|
140
148
|
|
141
|
-
res['responses'].map {|r| SearchResults.new(
|
149
|
+
res['responses'].map {|r| SearchResults.new(r)}
|
142
150
|
end
|
143
151
|
|
144
152
|
# Retrieves multiple documents, possibly from multiple indexes
|
data/lib/stretcher/version.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Stretcher::Alias do
|
4
|
+
|
5
|
+
let(:server) { Stretcher::Server.new(ES_URL, :logger => DEBUG_LOGGER) }
|
6
|
+
let(:index) { server.index(:foo) }
|
7
|
+
let(:my_alias) { index.alias('user-1') }
|
8
|
+
|
9
|
+
before do
|
10
|
+
index.type(:bar).put(1, { message: 'visible', user_id: 1 })
|
11
|
+
index.type(:bar).put(2, { message: 'hidden', user_id: 2 })
|
12
|
+
index.refresh
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'creating' do
|
16
|
+
|
17
|
+
before do
|
18
|
+
my_alias.create(filter: {
|
19
|
+
term: { user_id: 1 }
|
20
|
+
})
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should have the alias' do
|
24
|
+
my_alias.should exist
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'searching' do
|
30
|
+
|
31
|
+
it 'should be able to search with filter' do
|
32
|
+
resp = my_alias.index_context.search(:query => { :match_all => {} })
|
33
|
+
resp.results.map(&:message).should == ['visible']
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'destroying' do
|
39
|
+
|
40
|
+
before do
|
41
|
+
my_alias.delete
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should have removed the alias' do
|
45
|
+
my_alias.should_not exist
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Stretcher::Cluster do
|
4
|
+
|
5
|
+
let(:server) { Stretcher::Server.new(ES_URL, :logger => DEBUG_LOGGER) }
|
6
|
+
let(:cluster) { server.cluster }
|
7
|
+
|
8
|
+
describe :health do
|
9
|
+
|
10
|
+
it 'should return the health' do
|
11
|
+
cluster.health.should be_a Hashie::Mash
|
12
|
+
cluster.health.status.should_not be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -4,24 +4,7 @@ describe Stretcher::Index do
|
|
4
4
|
let(:server) {
|
5
5
|
Stretcher::Server.new(ES_URL, :logger => DEBUG_LOGGER)
|
6
6
|
}
|
7
|
-
let(:index) {
|
8
|
-
i = server.index('foo')
|
9
|
-
begin
|
10
|
-
i.delete
|
11
|
-
rescue Stretcher::RequestError::NotFound
|
12
|
-
end
|
13
|
-
server.refresh
|
14
|
-
i.create({
|
15
|
-
:settings => {
|
16
|
-
:number_of_shards => 1,
|
17
|
-
:number_of_replicas => 0
|
18
|
-
}
|
19
|
-
})
|
20
|
-
# Why do both? Doesn't hurt, and it fixes some races
|
21
|
-
server.refresh
|
22
|
-
i.refresh
|
23
|
-
i
|
24
|
-
}
|
7
|
+
let(:index) { ensure_test_index(server, :foo) }
|
25
8
|
let(:corpus) {
|
26
9
|
# underscore field that are not system fields should make it through to _source
|
27
10
|
[
|
@@ -104,6 +87,11 @@ describe Stretcher::Index do
|
|
104
87
|
create_tweet_mapping
|
105
88
|
end
|
106
89
|
|
90
|
+
it 'should be able to get mapping' do
|
91
|
+
index.get_mapping.should_not be_nil
|
92
|
+
index.get_mapping.foo.should_not be_nil
|
93
|
+
end
|
94
|
+
|
107
95
|
it "should retrieve settings properly" do
|
108
96
|
index.get_settings['foo']['settings']['index.number_of_shards'].should eq("1")
|
109
97
|
index.get_settings['foo']['settings']['index.number_of_replicas'].should eq("0")
|
@@ -2,8 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Stretcher::IndexType do
|
4
4
|
let(:server) { Stretcher::Server.new(ES_URL, :logger => DEBUG_LOGGER) }
|
5
|
-
let(:index) { server
|
6
|
-
|
5
|
+
let(:index) { ensure_test_index(server, :foo) }
|
7
6
|
let(:type) { index.type(:bar) }
|
8
7
|
|
9
8
|
it "should be existentially aware" do
|
@@ -46,8 +45,8 @@ describe Stretcher::IndexType do
|
|
46
45
|
|
47
46
|
it "should add _highlight field to resulting documents when present" do
|
48
47
|
res = type.search(:query => {:match => {:message => 'hello'}}, :highlight => {:fields => {:message => {}}})
|
49
|
-
res.
|
50
|
-
res.
|
48
|
+
res.pretty.first.message.should == @doc[:message]
|
49
|
+
res.pretty.first.should have_key '_highlight'
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
@@ -3,23 +3,24 @@ require 'spec_helper'
|
|
3
3
|
describe Stretcher::SearchResults do
|
4
4
|
let(:result) do
|
5
5
|
Hashie::Mash.new({
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
}
|
18
|
-
})
|
6
|
+
'facets' => [],
|
7
|
+
'hits' => {
|
8
|
+
'total' => 1,
|
9
|
+
'hits' => [{
|
10
|
+
'_score' => 255,
|
11
|
+
'_id' => 2,
|
12
|
+
'_index' => 'index_name',
|
13
|
+
'_type' => 'type_name'
|
14
|
+
}]
|
15
|
+
}
|
16
|
+
})
|
19
17
|
end
|
20
18
|
|
21
19
|
context 'merges in select keys' do
|
22
|
-
subject(:search_result) {
|
20
|
+
subject(:search_result) {
|
21
|
+
Stretcher::SearchResults.new(result).pretty.first
|
22
|
+
}
|
23
|
+
|
23
24
|
its(:_score) { should == 255 }
|
24
25
|
its(:_id) { should == 2 }
|
25
26
|
its(:_index) { should == 'index_name' }
|
data/spec/spec_helper.rb
CHANGED
@@ -8,3 +8,22 @@ File.open("test_logs", 'wb') {|f| f.write("")}
|
|
8
8
|
DEBUG_LOGGER = Logger.new('test_logs')
|
9
9
|
ES_URL = 'http://localhost:9200'
|
10
10
|
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib stretcher]))
|
11
|
+
|
12
|
+
def ensure_test_index(server, name)
|
13
|
+
i = server.index(name)
|
14
|
+
begin
|
15
|
+
i.delete
|
16
|
+
rescue Stretcher::RequestError::NotFound
|
17
|
+
end
|
18
|
+
server.refresh
|
19
|
+
i.create({
|
20
|
+
:settings => {
|
21
|
+
:number_of_shards => 1,
|
22
|
+
:number_of_replicas => 0
|
23
|
+
}
|
24
|
+
})
|
25
|
+
# Why do both? Doesn't hurt, and it fixes some races
|
26
|
+
server.refresh
|
27
|
+
i.refresh
|
28
|
+
i
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stretcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.20.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Cholakian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -179,6 +179,8 @@ files:
|
|
179
179
|
- README.md
|
180
180
|
- Rakefile
|
181
181
|
- lib/stretcher.rb
|
182
|
+
- lib/stretcher/alias.rb
|
183
|
+
- lib/stretcher/cluster.rb
|
182
184
|
- lib/stretcher/es_component.rb
|
183
185
|
- lib/stretcher/index.rb
|
184
186
|
- lib/stretcher/index_type.rb
|
@@ -187,6 +189,8 @@ files:
|
|
187
189
|
- lib/stretcher/server.rb
|
188
190
|
- lib/stretcher/util.rb
|
189
191
|
- lib/stretcher/version.rb
|
192
|
+
- spec/lib/stretcher_alias_spec.rb
|
193
|
+
- spec/lib/stretcher_cluster_spec.rb
|
190
194
|
- spec/lib/stretcher_index_spec.rb
|
191
195
|
- spec/lib/stretcher_index_type_spec.rb
|
192
196
|
- spec/lib/stretcher_search_results_spec.rb
|
@@ -209,9 +213,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
213
|
version: '0'
|
210
214
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
215
|
requirements:
|
212
|
-
- - '
|
216
|
+
- - '>'
|
213
217
|
- !ruby/object:Gem::Version
|
214
|
-
version:
|
218
|
+
version: 1.3.1
|
215
219
|
requirements: []
|
216
220
|
rubyforge_project:
|
217
221
|
rubygems_version: 2.0.2
|
@@ -220,6 +224,8 @@ specification_version: 4
|
|
220
224
|
summary: The elegant ElasticSearch client, supporting persistent connections, and
|
221
225
|
a clean DSL
|
222
226
|
test_files:
|
227
|
+
- spec/lib/stretcher_alias_spec.rb
|
228
|
+
- spec/lib/stretcher_cluster_spec.rb
|
223
229
|
- spec/lib/stretcher_index_spec.rb
|
224
230
|
- spec/lib/stretcher_index_type_spec.rb
|
225
231
|
- spec/lib/stretcher_search_results_spec.rb
|