es 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aedff15c022fdb35b354b4c66acc8df3bf23b5b3
4
+ data.tar.gz: 3f0ef61e76cc3c95dcf3b10cc9d5cdfa87d2d5a0
5
+ SHA512:
6
+ metadata.gz: 5565291652fdc30e7feb9c1d98592740dd22e4949af5d51cf6ca2a5710a52fd2c9b9769066d6ccb0854d4abe090c5d08fffc23c5866bab58ee3a0b7984424053
7
+ data.tar.gz: aeed8c939fe7e0ffbc29677cd11f4cafda4b5d02423608af7567e726e5eba551a1b0a8350acf941559b3a17b1338c9e6ce795b4ea3a54970118e3506e2cc5740
data/lib/es.rb CHANGED
@@ -1,10 +1,11 @@
1
- require 'es/version'
2
- require 'es/connection'
3
- require 'es/raw_client'
4
- require 'es/client'
5
-
6
1
  module ES
7
2
  def self.new(*args) # faux constructor
8
3
  Client.new(*args)
9
4
  end
10
5
  end
6
+
7
+ require 'es/version'
8
+ require 'es/connection'
9
+ require 'es/raw_client'
10
+ require 'es/client'
11
+ require 'es/utils'
@@ -29,9 +29,14 @@ module ES
29
29
  @dumper.load(response)
30
30
  end
31
31
 
32
- def search(path, data)
32
+ def search(path, data, params = {})
33
33
  serialized = serialize(data)
34
- response = @client.search(path, serialized)
34
+ response = @client.search(path, serialized, params)
35
+ @dumper.load(response)
36
+ end
37
+
38
+ def scroll(params = {})
39
+ response = @client.scroll(params)
35
40
  @dumper.load(response)
36
41
  end
37
42
 
@@ -52,6 +57,11 @@ module ES
52
57
  @dumper.load(response)
53
58
  end
54
59
 
60
+ def get_mapping(path)
61
+ response = @client.get_mapping(path)
62
+ @dumper.load(response)
63
+ end
64
+
55
65
  private
56
66
  def serialize(data)
57
67
  @dumper.dump(data, mode: :compat)
@@ -24,8 +24,12 @@ module ES
24
24
  @connection.request(:put, path, data)
25
25
  end
26
26
 
27
- def search(path, query)
28
- @connection.request(:post, action_path(path, :search), query)
27
+ def search(path, query, params = {})
28
+ @connection.request(:post, action_path(path, :search, params), query)
29
+ end
30
+
31
+ def scroll(params = {})
32
+ @connection.request(:get, action_path(nil, 'search/scroll', params))
29
33
  end
30
34
 
31
35
  def update(path, data)
@@ -36,9 +40,18 @@ module ES
36
40
  @connection.request(:post, action_path(path, :bulk), requests)
37
41
  end
38
42
 
43
+ def get_mapping(path)
44
+ @connection.request(:get, action_path(path, :mapping))
45
+ end
46
+
39
47
  private
40
- def action_path(path, action)
41
- path ? "#{path}/_#{action}" : "_#{action}"
48
+ def action_path(path, action, params = {})
49
+ full_path = path ? "#{path}/_#{action}" : "_#{action}"
50
+ params.any? ? "#{full_path}?#{serialize_params(params)}" : full_path
51
+ end
52
+
53
+ def serialize_params(params)
54
+ params.map { |k, v| "#{k}=#{v}" }.join('&')
42
55
  end
43
56
  end
44
57
  end
@@ -0,0 +1,23 @@
1
+ module ES
2
+ def self.copy_index(from_index, to_index, opts = {})
3
+ scroll_timeout = opts.fetch(:scroll_timeout, '5m')
4
+ scroll_size = opts.fetch(:scroll_size, 100)
5
+
6
+ from = new(host: opts[:from_host])
7
+ to = new(host: opts[:to_host])
8
+
9
+ results = from.search(from_index, {query: {match_all: {}}}, {scroll: scroll_timeout, size: scroll_size})
10
+
11
+ while results['hits']['hits'].any?
12
+ requests = results['hits']['hits'].each_with_object([]) do |hit, requests|
13
+ requests << {index: {_type: hit['_type'], _id: hit['id']}}
14
+ requests << hit['_source']
15
+ end
16
+
17
+ to.bulk(requests, to_index)
18
+
19
+ scroll_id = results['_scroll_id']
20
+ results = from.scroll(scroll: scroll_timeout, scroll_id: scroll_id)
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module ES
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -42,9 +42,15 @@ describe ES::Client do
42
42
  end
43
43
 
44
44
  it 'serializes data for .search' do
45
- client.should_receive(:search).with('index/1', raw_data).and_return(raw_response)
45
+ client.should_receive(:search).with('index/1', raw_data, {size: 20}).and_return(raw_response)
46
46
 
47
- subject.search('index/1', data).should == response
47
+ subject.search('index/1', data, size: 20).should == response
48
+ end
49
+
50
+ it 'serializes data from .scroll' do
51
+ client.should_receive(:scroll).with({scroll_id: 123}).and_return(raw_response)
52
+
53
+ subject.scroll(scroll_id: 123)
48
54
  end
49
55
 
50
56
  it 'serializes data for .update' do
@@ -52,4 +58,16 @@ describe ES::Client do
52
58
 
53
59
  subject.update('index/1', data).should == response
54
60
  end
61
+
62
+ it 'unserializes response for .get_mapping' do
63
+ client.should_receive(:get_mapping).with('index').and_return(raw_response)
64
+
65
+ subject.get_mapping('index').should == response
66
+ end
67
+
68
+ it 'should respond to all methods of raw client' do
69
+ ES::RawClient.instance_methods(false).each do |method|
70
+ subject.respond_to?(method).should be_true, "expected to respond to message #{method}"
71
+ end
72
+ end
55
73
  end
@@ -3,7 +3,7 @@ require 'es/connection'
3
3
  describe ES::Connection do
4
4
  let(:data) { :data }
5
5
  let(:response_body) { :response }
6
- let(:response) { stub(response_code: 200, body_str: response_body) }
6
+ let(:response) { double(response_code: 200, body_str: response_body) }
7
7
  let(:driver) { double(:Driver) }
8
8
 
9
9
  subject { described_class.new('http://localhost:9200', driver) }
@@ -33,7 +33,7 @@ describe ES::Connection do
33
33
  end
34
34
 
35
35
  it 'throws error if response code is not 2XX' do
36
- error_response = stub(response_code: 400)
36
+ error_response = double(response_code: 400)
37
37
  driver.should_receive(:http_post).and_return(error_response)
38
38
 
39
39
  expect { subject.request(:post, 'index/_search', data) }.to raise_error(ES::Connection::Error)
@@ -44,6 +44,20 @@ describe ES::RawClient do
44
44
 
45
45
  subject.search('index', data).should == response
46
46
  end
47
+
48
+ it 'sends POST to connection with parameters' do
49
+ connection.should_receive(:request).with(:post, 'index/_search?scroll=5m&size=100', data).and_return(response)
50
+
51
+ subject.search('index', data, scroll: '5m', size: 100)
52
+ end
53
+ end
54
+
55
+ context '.scroll' do
56
+ it 'sends GET to connection with parameters' do
57
+ connection.should_receive(:request).with(:get, '_search/scroll?scroll=5m&scroll_id=123').and_return(response)
58
+
59
+ subject.scroll(scroll: '5m', scroll_id: 123)
60
+ end
47
61
  end
48
62
 
49
63
  context '.bulk' do
@@ -61,4 +75,12 @@ describe ES::RawClient do
61
75
  subject.update('index/1', data).should == response
62
76
  end
63
77
  end
78
+
79
+ context '.get_mapping' do
80
+ it 'sends GET to connection' do
81
+ connection.should_receive(:request).with(:get, 'index/_mapping').and_return(response)
82
+
83
+ subject.get_mapping('index').should == response
84
+ end
85
+ end
64
86
  end
metadata CHANGED
@@ -1,80 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: es
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.7
4
+ version: 0.0.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jan Suchal
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-26 00:00:00.000000000 Z
11
+ date: 2013-09-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: oj
16
- version_requirements: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
15
  requirement: !ruby/object:Gem::Requirement
23
- none: false
24
16
  requirements:
25
- - - ! '>='
17
+ - - '>='
26
18
  - !ruby/object:Gem::Version
27
19
  version: '0'
28
20
  type: :runtime
29
21
  prerelease: false
30
- - !ruby/object:Gem::Dependency
31
- name: curb
32
22
  version_requirements: !ruby/object:Gem::Requirement
33
- none: false
34
23
  requirements:
35
- - - ! '>='
24
+ - - '>='
36
25
  - !ruby/object:Gem::Version
37
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: curb
38
29
  requirement: !ruby/object:Gem::Requirement
39
- none: false
40
30
  requirements:
41
- - - ! '>='
31
+ - - '>='
42
32
  - !ruby/object:Gem::Version
43
33
  version: '0'
44
34
  type: :runtime
45
35
  prerelease: false
46
- - !ruby/object:Gem::Dependency
47
- name: rspec
48
36
  version_requirements: !ruby/object:Gem::Requirement
49
- none: false
50
37
  requirements:
51
- - - ! '>='
38
+ - - '>='
52
39
  - !ruby/object:Gem::Version
53
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
54
43
  requirement: !ruby/object:Gem::Requirement
55
- none: false
56
44
  requirements:
57
- - - ! '>='
45
+ - - '>='
58
46
  - !ruby/object:Gem::Version
59
47
  version: '0'
60
48
  type: :development
61
49
  prerelease: false
62
- - !ruby/object:Gem::Dependency
63
- name: rake
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
- none: false
66
51
  requirements:
67
- - - ! '>='
52
+ - - '>='
68
53
  - !ruby/object:Gem::Version
69
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
70
57
  requirement: !ruby/object:Gem::Requirement
71
- none: false
72
58
  requirements:
73
- - - ! '>='
59
+ - - '>='
74
60
  - !ruby/object:Gem::Version
75
61
  version: '0'
76
62
  type: :development
77
63
  prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
78
69
  description: Simple wrapper for elasticsearch
79
70
  email:
80
71
  - johno@jsmf.net
@@ -92,33 +83,33 @@ files:
92
83
  - lib/es/client.rb
93
84
  - lib/es/connection.rb
94
85
  - lib/es/raw_client.rb
86
+ - lib/es/utils.rb
95
87
  - lib/es/version.rb
96
88
  - spec/es/client_spec.rb
97
89
  - spec/es/connection_spec.rb
98
90
  - spec/es/raw_client_spec.rb
99
91
  homepage: http://github.com/minio-sk/es
100
92
  licenses: []
93
+ metadata: {}
101
94
  post_install_message:
102
95
  rdoc_options: []
103
96
  require_paths:
104
97
  - lib
105
98
  required_ruby_version: !ruby/object:Gem::Requirement
106
- none: false
107
99
  requirements:
108
- - - ! '>='
100
+ - - '>='
109
101
  - !ruby/object:Gem::Version
110
102
  version: '0'
111
103
  required_rubygems_version: !ruby/object:Gem::Requirement
112
- none: false
113
104
  requirements:
114
- - - ! '>='
105
+ - - '>='
115
106
  - !ruby/object:Gem::Version
116
107
  version: '0'
117
108
  requirements: []
118
109
  rubyforge_project:
119
- rubygems_version: 1.8.25
110
+ rubygems_version: 2.0.3
120
111
  signing_key:
121
- specification_version: 3
112
+ specification_version: 4
122
113
  summary: Simple wrapper for elasticsearch.
123
114
  test_files:
124
115
  - spec/es/client_spec.rb