elasticsearch-api 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +160 -0
- data/Rakefile +62 -0
- data/elasticsearch-api.gemspec +51 -0
- data/lib/elasticsearch-api +1 -0
- data/lib/elasticsearch/api.rb +23 -0
- data/lib/elasticsearch/api/actions/bulk.rb +71 -0
- data/lib/elasticsearch/api/actions/cluster/get_settings.rb +21 -0
- data/lib/elasticsearch/api/actions/cluster/health.rb +50 -0
- data/lib/elasticsearch/api/actions/cluster/node_hot_threads.rb +46 -0
- data/lib/elasticsearch/api/actions/cluster/node_info.rb +59 -0
- data/lib/elasticsearch/api/actions/cluster/node_shutdown.rb +36 -0
- data/lib/elasticsearch/api/actions/cluster/node_stats.rb +77 -0
- data/lib/elasticsearch/api/actions/cluster/put_settings.rb +28 -0
- data/lib/elasticsearch/api/actions/cluster/reroute.rb +44 -0
- data/lib/elasticsearch/api/actions/cluster/state.rb +47 -0
- data/lib/elasticsearch/api/actions/count.rb +46 -0
- data/lib/elasticsearch/api/actions/create.rb +34 -0
- data/lib/elasticsearch/api/actions/delete.rb +61 -0
- data/lib/elasticsearch/api/actions/delete_by_query.rb +62 -0
- data/lib/elasticsearch/api/actions/exists.rb +51 -0
- data/lib/elasticsearch/api/actions/explain.rb +71 -0
- data/lib/elasticsearch/api/actions/get.rb +59 -0
- data/lib/elasticsearch/api/actions/get_source.rb +59 -0
- data/lib/elasticsearch/api/actions/index.rb +81 -0
- data/lib/elasticsearch/api/actions/indices/analyze.rb +63 -0
- data/lib/elasticsearch/api/actions/indices/clear_cache.rb +69 -0
- data/lib/elasticsearch/api/actions/indices/close.rb +35 -0
- data/lib/elasticsearch/api/actions/indices/create.rb +83 -0
- data/lib/elasticsearch/api/actions/indices/delete.rb +48 -0
- data/lib/elasticsearch/api/actions/indices/delete_alias.rb +37 -0
- data/lib/elasticsearch/api/actions/indices/delete_mapping.rb +26 -0
- data/lib/elasticsearch/api/actions/indices/delete_template.rb +33 -0
- data/lib/elasticsearch/api/actions/indices/delete_warmer.rb +32 -0
- data/lib/elasticsearch/api/actions/indices/exists.rb +35 -0
- data/lib/elasticsearch/api/actions/indices/exists_alias.rb +41 -0
- data/lib/elasticsearch/api/actions/indices/exists_type.rb +39 -0
- data/lib/elasticsearch/api/actions/indices/flush.rb +40 -0
- data/lib/elasticsearch/api/actions/indices/get_alias.rb +41 -0
- data/lib/elasticsearch/api/actions/indices/get_aliases.rb +32 -0
- data/lib/elasticsearch/api/actions/indices/get_mapping.rb +36 -0
- data/lib/elasticsearch/api/actions/indices/get_settings.rb +32 -0
- data/lib/elasticsearch/api/actions/indices/get_template.rb +30 -0
- data/lib/elasticsearch/api/actions/indices/get_warmer.rb +44 -0
- data/lib/elasticsearch/api/actions/indices/open.rb +33 -0
- data/lib/elasticsearch/api/actions/indices/optimize.rb +57 -0
- data/lib/elasticsearch/api/actions/indices/put_alias.rb +43 -0
- data/lib/elasticsearch/api/actions/indices/put_mapping.rb +49 -0
- data/lib/elasticsearch/api/actions/indices/put_settings.rb +45 -0
- data/lib/elasticsearch/api/actions/indices/put_template.rb +40 -0
- data/lib/elasticsearch/api/actions/indices/put_warmer.rb +48 -0
- data/lib/elasticsearch/api/actions/indices/refresh.rb +43 -0
- data/lib/elasticsearch/api/actions/indices/segments.rb +33 -0
- data/lib/elasticsearch/api/actions/indices/snapshot_index.rb +32 -0
- data/lib/elasticsearch/api/actions/indices/stats.rb +96 -0
- data/lib/elasticsearch/api/actions/indices/status.rb +46 -0
- data/lib/elasticsearch/api/actions/indices/update_aliases.rb +49 -0
- data/lib/elasticsearch/api/actions/indices/validate_query.rb +68 -0
- data/lib/elasticsearch/api/actions/info.rb +19 -0
- data/lib/elasticsearch/api/actions/mget.rb +64 -0
- data/lib/elasticsearch/api/actions/mlt.rb +86 -0
- data/lib/elasticsearch/api/actions/msearch.rb +75 -0
- data/lib/elasticsearch/api/actions/percolate.rb +57 -0
- data/lib/elasticsearch/api/actions/ping.rb +29 -0
- data/lib/elasticsearch/api/actions/scroll.rb +44 -0
- data/lib/elasticsearch/api/actions/search.rb +145 -0
- data/lib/elasticsearch/api/actions/suggest.rb +46 -0
- data/lib/elasticsearch/api/actions/update.rb +103 -0
- data/lib/elasticsearch/api/namespace/cluster.rb +20 -0
- data/lib/elasticsearch/api/namespace/common.rb +27 -0
- data/lib/elasticsearch/api/namespace/indices.rb +20 -0
- data/lib/elasticsearch/api/utils.rb +97 -0
- data/lib/elasticsearch/api/version.rb +5 -0
- data/test/integration/yaml_test_runner.rb +330 -0
- data/test/test_helper.rb +52 -0
- data/test/unit/bulk_test.rb +85 -0
- data/test/unit/client_test.rb +31 -0
- data/test/unit/cluster/get_settings_test.rb +26 -0
- data/test/unit/cluster/health_test.rb +38 -0
- data/test/unit/cluster/node_hot_threads_test.rb +35 -0
- data/test/unit/cluster/node_info_test.rb +45 -0
- data/test/unit/cluster/node_shutdown_test.rb +45 -0
- data/test/unit/cluster/node_stats_test.rb +65 -0
- data/test/unit/cluster/put_settings_test.rb +26 -0
- data/test/unit/cluster/reroute_test.rb +38 -0
- data/test/unit/cluster/state_test.rb +37 -0
- data/test/unit/count_test.rb +46 -0
- data/test/unit/create_document_test.rb +38 -0
- data/test/unit/delete_by_query_test.rb +42 -0
- data/test/unit/delete_document_test.rb +62 -0
- data/test/unit/exists_document_test.rb +76 -0
- data/test/unit/explain_document_test.rb +64 -0
- data/test/unit/get_document_source_test.rb +62 -0
- data/test/unit/get_document_test.rb +62 -0
- data/test/unit/hashie_test.rb +78 -0
- data/test/unit/index_document_test.rb +77 -0
- data/test/unit/indices/analyze_test.rb +67 -0
- data/test/unit/indices/clear_cache_test.rb +45 -0
- data/test/unit/indices/close_test.rb +42 -0
- data/test/unit/indices/create_test.rb +42 -0
- data/test/unit/indices/delete_alias_test.rb +38 -0
- data/test/unit/indices/delete_mapping_test.rb +47 -0
- data/test/unit/indices/delete_template_test.rb +26 -0
- data/test/unit/indices/delete_test.rb +45 -0
- data/test/unit/indices/delete_warmer_test.rb +59 -0
- data/test/unit/indices/exists_alias_test.rb +65 -0
- data/test/unit/indices/exists_test.rb +57 -0
- data/test/unit/indices/exists_type_test.rb +59 -0
- data/test/unit/indices/flush_test.rb +45 -0
- data/test/unit/indices/get_alias_test.rb +41 -0
- data/test/unit/indices/get_aliases_test.rb +35 -0
- data/test/unit/indices/get_mapping_test.rb +53 -0
- data/test/unit/indices/get_settings_test.rb +35 -0
- data/test/unit/indices/get_template_test.rb +32 -0
- data/test/unit/indices/get_warmer_test.rb +41 -0
- data/test/unit/indices/open_test.rb +42 -0
- data/test/unit/indices/optimize_test.rb +45 -0
- data/test/unit/indices/put_alias_test.rb +47 -0
- data/test/unit/indices/put_mapping_test.rb +57 -0
- data/test/unit/indices/put_settings_test.rb +50 -0
- data/test/unit/indices/put_template_test.rb +48 -0
- data/test/unit/indices/put_warmer_test.rb +62 -0
- data/test/unit/indices/refresh_test.rb +55 -0
- data/test/unit/indices/segments_test.rb +55 -0
- data/test/unit/indices/snapshot_index_test.rb +55 -0
- data/test/unit/indices/stats_test.rb +76 -0
- data/test/unit/indices/status_test.rb +55 -0
- data/test/unit/indices/update_aliases_test.rb +42 -0
- data/test/unit/indices/validate_query_test.rb +75 -0
- data/test/unit/info_test.rb +26 -0
- data/test/unit/json_builders_test.rb +64 -0
- data/test/unit/mget_test.rb +70 -0
- data/test/unit/mlt_test.rb +80 -0
- data/test/unit/msearch_test.rb +120 -0
- data/test/unit/percolate_test.rb +49 -0
- data/test/unit/ping_test.rb +48 -0
- data/test/unit/scroll_test.rb +26 -0
- data/test/unit/search_test.rb +93 -0
- data/test/unit/suggest_test.rb +55 -0
- data/test/unit/update_document_test.rb +62 -0
- data/test/unit/utils_test.rb +118 -0
- metadata +498 -0
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
class MltTest < ::Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "More Like This" do
|
8
|
+
subject { FakeClient.new }
|
9
|
+
|
10
|
+
should "require the :index argument" do
|
11
|
+
assert_raise ArgumentError do
|
12
|
+
subject.mlt :type => 'bar', :id => '1'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
should "require the :type argument" do
|
17
|
+
assert_raise ArgumentError do
|
18
|
+
subject.mlt :index => 'foo', :id => '1'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
should "require the :id argument" do
|
23
|
+
assert_raise ArgumentError do
|
24
|
+
subject.mlt :index => 'foo', :type => 'bar'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
should "perform correct request" do
|
29
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
30
|
+
assert_equal 'GET', method
|
31
|
+
assert_equal 'foo/bar/1/_mlt', url
|
32
|
+
assert_equal Hash.new, params
|
33
|
+
assert_nil body
|
34
|
+
true
|
35
|
+
end.returns(FakeResponse.new)
|
36
|
+
|
37
|
+
subject.mlt :index => 'foo', :type => 'bar', :id => '1'
|
38
|
+
end
|
39
|
+
|
40
|
+
should "pass the URL parameters" do
|
41
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
42
|
+
assert_equal 'foo/bar/1/_mlt', url
|
43
|
+
assert_equal 1, params[:max_doc_freq]
|
44
|
+
true
|
45
|
+
end.returns(FakeResponse.new)
|
46
|
+
|
47
|
+
subject.mlt :index => 'foo', :type => 'bar', :id => '1', :max_doc_freq => 1
|
48
|
+
end
|
49
|
+
|
50
|
+
should "pass the specific parameters as a list" do
|
51
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
52
|
+
assert_equal 'foo,bar', params[:mlt_fields]
|
53
|
+
assert_equal 'A,B', params[:search_indices]
|
54
|
+
assert_equal 'X,Y', params[:search_types]
|
55
|
+
assert_equal 'lam,bam', params[:stop_words]
|
56
|
+
true
|
57
|
+
end.returns(FakeResponse.new)
|
58
|
+
|
59
|
+
subject.mlt :index => 'foo', :type => 'bar', :id => '1',
|
60
|
+
:mlt_fields => ['foo', 'bar'],
|
61
|
+
:search_indices => ['A', 'B'],
|
62
|
+
:search_types => ['X', 'Y'],
|
63
|
+
:stop_words => ['lam','bam']
|
64
|
+
end
|
65
|
+
|
66
|
+
should "pass a specific search definition in body" do
|
67
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
68
|
+
assert_equal 'foo/bar/1/_mlt', url
|
69
|
+
assert_equal Hash.new, body[:query]
|
70
|
+
true
|
71
|
+
end.returns(FakeResponse.new)
|
72
|
+
|
73
|
+
subject.mlt :index => 'foo', :type => 'bar', :id => '1', :body => { :query => {} }
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
class MsearchTest < ::Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "Msearch" do
|
8
|
+
subject { FakeClient.new }
|
9
|
+
|
10
|
+
should "require the :body argument" do
|
11
|
+
assert_raise ArgumentError do
|
12
|
+
subject.msearch
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
should "post correct payload to the endpoint" do
|
17
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
18
|
+
assert_equal 'GET', method
|
19
|
+
assert_equal '_msearch', url
|
20
|
+
assert_equal Hash.new, params
|
21
|
+
assert_equal <<-PAYLOAD.gsub(/^\s+/, ''), body
|
22
|
+
{"index":"foo"}
|
23
|
+
{"query":{"match_all":{}}}
|
24
|
+
{"index":"bar"}
|
25
|
+
{"query":{"match":{"foo":"bar"}}}
|
26
|
+
{"search_type":"count"}
|
27
|
+
{"facets":{"tags":{}}}
|
28
|
+
PAYLOAD
|
29
|
+
true
|
30
|
+
end.returns(FakeResponse.new)
|
31
|
+
|
32
|
+
subject.msearch :body => [
|
33
|
+
{ :index => 'foo', :search => { :query => { :match_all => {} } } },
|
34
|
+
{ :index => 'bar', :search => { :query => { :match => { :foo => 'bar' } } } },
|
35
|
+
{ :search_type => 'count', :search => { :facets => { :tags => {} } } }
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
should "post a string payload intact" do
|
40
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
41
|
+
assert_equal %Q|{"foo":"bar"}\n{"moo":"lam"}|, body
|
42
|
+
true
|
43
|
+
end.returns(FakeResponse.new)
|
44
|
+
|
45
|
+
subject.msearch :body => %Q|{"foo":"bar"}\n{"moo":"lam"}|
|
46
|
+
end
|
47
|
+
|
48
|
+
should "serialize and post header/data pairs" do
|
49
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
50
|
+
assert_equal 'GET', method
|
51
|
+
assert_equal '_msearch', url
|
52
|
+
assert_equal Hash.new, params
|
53
|
+
assert_equal <<-PAYLOAD.gsub(/^\s+/, ''), body
|
54
|
+
{"index":"foo"}
|
55
|
+
{"query":{"match_all":{}}}
|
56
|
+
{"index":"bar"}
|
57
|
+
{"query":{"match":{"foo":"bar"}}}
|
58
|
+
PAYLOAD
|
59
|
+
true
|
60
|
+
end.returns(FakeResponse.new)
|
61
|
+
|
62
|
+
subject.msearch :body => [
|
63
|
+
{ :index => 'foo' },
|
64
|
+
{ :query => { :match_all => {} } },
|
65
|
+
{ :index => 'bar' },
|
66
|
+
{ :query => { :match => { :foo => 'bar' } } }
|
67
|
+
]
|
68
|
+
end
|
69
|
+
|
70
|
+
should "perform request against an index" do
|
71
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
72
|
+
assert_equal 'foo/_msearch', url
|
73
|
+
true
|
74
|
+
end.returns(FakeResponse.new)
|
75
|
+
|
76
|
+
subject.msearch :index => 'foo', :body => []
|
77
|
+
end
|
78
|
+
|
79
|
+
should "perform request against an index and type" do
|
80
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
81
|
+
assert_equal 'foo/bar/_msearch', url
|
82
|
+
true
|
83
|
+
end.returns(FakeResponse.new)
|
84
|
+
|
85
|
+
subject.msearch :index => 'foo', :type => 'bar', :body => []
|
86
|
+
end
|
87
|
+
|
88
|
+
should "perform request against multiple indices" do
|
89
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
90
|
+
assert_equal 'foo,bar/_msearch', url
|
91
|
+
true
|
92
|
+
end.returns(FakeResponse.new)
|
93
|
+
|
94
|
+
subject.msearch :index => ['foo', 'bar'], :body => []
|
95
|
+
end
|
96
|
+
|
97
|
+
should "perform request against multiple indices and types" do
|
98
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
99
|
+
assert_equal 'foo,bar/lam,bam/_msearch', url
|
100
|
+
true
|
101
|
+
end.returns(FakeResponse.new)
|
102
|
+
|
103
|
+
subject.msearch :index => ['foo', 'bar'], :type => ['lam', 'bam'], :body => []
|
104
|
+
end
|
105
|
+
|
106
|
+
should "encode URL parameters" do
|
107
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
108
|
+
assert_equal '_msearch', url
|
109
|
+
assert_equal 'scroll', params[:search_type]
|
110
|
+
true
|
111
|
+
end.returns(FakeResponse.new)
|
112
|
+
|
113
|
+
subject.msearch :body => [], :search_type => 'scroll'
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
class PercolateTest < ::Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "Percolate" do
|
8
|
+
subject { FakeClient.new }
|
9
|
+
|
10
|
+
should "require the :index argument" do
|
11
|
+
assert_raise ArgumentError do
|
12
|
+
subject.percolate :type => 'bar', :body => {}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
should "require the :body argument" do
|
17
|
+
assert_raise ArgumentError do
|
18
|
+
subject.percolate :index => 'bar'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have default document type" do
|
23
|
+
assert_nothing_raised do
|
24
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
25
|
+
assert_equal 'foo/document/_percolate', url
|
26
|
+
true
|
27
|
+
end.returns(FakeResponse.new)
|
28
|
+
|
29
|
+
subject.percolate :index => 'foo', :body => {}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
should "perform correct request" do
|
34
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
35
|
+
assert_equal 'GET', method
|
36
|
+
assert_equal 'foo/bar/_percolate', url
|
37
|
+
assert_equal Hash.new, params
|
38
|
+
assert_equal 'bar', body[:doc][:foo]
|
39
|
+
true
|
40
|
+
end.returns(FakeResponse.new)
|
41
|
+
|
42
|
+
subject.percolate :index => 'foo', :type => 'bar', :body => { :doc => { :foo => 'bar' } }
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
class PingTest < ::Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "Indices: Exists" do
|
8
|
+
subject { FakeClient.new }
|
9
|
+
|
10
|
+
should "perform correct request" do
|
11
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
12
|
+
assert_equal 'HEAD', method
|
13
|
+
assert_equal '', url
|
14
|
+
assert_equal Hash.new, params
|
15
|
+
assert_nil body
|
16
|
+
true
|
17
|
+
end.returns(FakeResponse.new)
|
18
|
+
|
19
|
+
subject.ping
|
20
|
+
end
|
21
|
+
|
22
|
+
should "return true for successful response" do
|
23
|
+
subject.expects(:perform_request).returns(FakeResponse.new 200, 'OK')
|
24
|
+
assert_equal true, subject.ping
|
25
|
+
end
|
26
|
+
|
27
|
+
should "return false for 404 response" do
|
28
|
+
subject.expects(:perform_request).returns(FakeResponse.new 404, 'Not Found')
|
29
|
+
assert_equal false, subject.ping
|
30
|
+
end
|
31
|
+
|
32
|
+
should "return false on 'not found' exceptions" do
|
33
|
+
subject.expects(:perform_request).raises(StandardError.new '404 NotFound')
|
34
|
+
assert_equal false, subject.ping
|
35
|
+
end
|
36
|
+
|
37
|
+
should "re-raise generic exceptions" do
|
38
|
+
subject.expects(:perform_request).raises(StandardError)
|
39
|
+
assert_raise(StandardError) do
|
40
|
+
assert_equal false, subject.ping
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
class ScrollTest < ::Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "Scroll" do
|
8
|
+
subject { FakeClient.new }
|
9
|
+
|
10
|
+
should "perform correct request" do
|
11
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
12
|
+
assert_equal 'GET', method
|
13
|
+
assert_equal '_search/scroll', url
|
14
|
+
assert_equal 'cXVlcn...', params[:scroll_id]
|
15
|
+
assert_nil body
|
16
|
+
true
|
17
|
+
end.returns(FakeResponse.new)
|
18
|
+
|
19
|
+
subject.scroll :scroll_id => 'cXVlcn...'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
class SearchTest < ::Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "Search" do
|
8
|
+
subject { FakeClient.new }
|
9
|
+
|
10
|
+
should "perform correct request" do
|
11
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
12
|
+
assert_equal 'GET', method
|
13
|
+
assert_equal '_search', url
|
14
|
+
assert_equal Hash.new, params
|
15
|
+
assert_nil body
|
16
|
+
true
|
17
|
+
end.returns(FakeResponse.new)
|
18
|
+
|
19
|
+
subject.search
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have default value for index" do
|
23
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
24
|
+
assert_equal 'GET', method
|
25
|
+
assert_equal '_all/foo/_search', url
|
26
|
+
true
|
27
|
+
end.returns(FakeResponse.new)
|
28
|
+
|
29
|
+
subject.search type: 'foo'
|
30
|
+
end
|
31
|
+
|
32
|
+
should "post a request definition in body" do
|
33
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
34
|
+
assert_equal :match, body[:query].keys.first
|
35
|
+
true
|
36
|
+
end.returns(FakeResponse.new)
|
37
|
+
|
38
|
+
subject.search :body => { :query => { :match => {} } }
|
39
|
+
end
|
40
|
+
|
41
|
+
should "perform request against an index" do
|
42
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
43
|
+
assert_equal 'foo/_search', url
|
44
|
+
true
|
45
|
+
end.returns(FakeResponse.new)
|
46
|
+
|
47
|
+
subject.search :index => 'foo'
|
48
|
+
end
|
49
|
+
|
50
|
+
should "perform request against an index and type" do
|
51
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
52
|
+
assert_equal 'foo/bar/_search', url
|
53
|
+
true
|
54
|
+
end.returns(FakeResponse.new)
|
55
|
+
|
56
|
+
subject.search :index => 'foo', :type => 'bar'
|
57
|
+
end
|
58
|
+
|
59
|
+
should "perform request against multiple indices" do
|
60
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
61
|
+
assert_equal 'foo,bar/_search', url
|
62
|
+
true
|
63
|
+
end.returns(FakeResponse.new).twice
|
64
|
+
|
65
|
+
subject.search :index => ['foo', 'bar']
|
66
|
+
subject.search :index => 'foo,bar'
|
67
|
+
end
|
68
|
+
|
69
|
+
should "perform request against multiple indices and types" do
|
70
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
71
|
+
assert_equal 'foo,bar/lam,bam/_search', url
|
72
|
+
true
|
73
|
+
end.returns(FakeResponse.new).twice
|
74
|
+
|
75
|
+
subject.search :index => ['foo', 'bar'], :type => ['lam', 'bam']
|
76
|
+
subject.search :index => 'foo,bar', :type => 'lam,bam'
|
77
|
+
end
|
78
|
+
|
79
|
+
should "encode URL parameters" do
|
80
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
81
|
+
assert_equal '_search', url
|
82
|
+
assert_equal 'count', params[:search_type]
|
83
|
+
true
|
84
|
+
end.returns(FakeResponse.new)
|
85
|
+
|
86
|
+
subject.search :search_type => 'count'
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
class SuggestTest < ::Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "Suggest" do
|
8
|
+
subject { FakeClient.new }
|
9
|
+
|
10
|
+
should "perform correct request" do
|
11
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
12
|
+
assert_equal 'POST', method
|
13
|
+
assert_equal '_suggest', url
|
14
|
+
assert_equal Hash.new, params
|
15
|
+
assert_equal Hash.new, body
|
16
|
+
true
|
17
|
+
end.returns(FakeResponse.new)
|
18
|
+
|
19
|
+
subject.suggest :body => {}
|
20
|
+
end
|
21
|
+
|
22
|
+
should "perform request against an index" do
|
23
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
24
|
+
assert_equal 'foo/_suggest', url
|
25
|
+
true
|
26
|
+
end.returns(FakeResponse.new)
|
27
|
+
|
28
|
+
subject.suggest :index => 'foo', :body => {}
|
29
|
+
end
|
30
|
+
|
31
|
+
should "pass the URL parameters" do
|
32
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
33
|
+
assert_equal 'foo/_suggest', url
|
34
|
+
assert_equal 'abc123', params[:routing]
|
35
|
+
true
|
36
|
+
end.returns(FakeResponse.new)
|
37
|
+
|
38
|
+
subject.suggest :index => 'foo', :routing => 'abc123', :body => {}
|
39
|
+
end
|
40
|
+
|
41
|
+
should "pass the request definition in the body" do
|
42
|
+
subject.expects(:perform_request).with do |method, url, params, body|
|
43
|
+
assert_equal '_suggest', url
|
44
|
+
assert_equal 'tset', body[:my_suggest][:text]
|
45
|
+
true
|
46
|
+
end.returns(FakeResponse.new)
|
47
|
+
|
48
|
+
subject.suggest :body => { :my_suggest => { :text => 'tset' } }
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|