elasticsearch-api 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +13 -0
  5. data/README.md +160 -0
  6. data/Rakefile +62 -0
  7. data/elasticsearch-api.gemspec +51 -0
  8. data/lib/elasticsearch-api +1 -0
  9. data/lib/elasticsearch/api.rb +23 -0
  10. data/lib/elasticsearch/api/actions/bulk.rb +71 -0
  11. data/lib/elasticsearch/api/actions/cluster/get_settings.rb +21 -0
  12. data/lib/elasticsearch/api/actions/cluster/health.rb +50 -0
  13. data/lib/elasticsearch/api/actions/cluster/node_hot_threads.rb +46 -0
  14. data/lib/elasticsearch/api/actions/cluster/node_info.rb +59 -0
  15. data/lib/elasticsearch/api/actions/cluster/node_shutdown.rb +36 -0
  16. data/lib/elasticsearch/api/actions/cluster/node_stats.rb +77 -0
  17. data/lib/elasticsearch/api/actions/cluster/put_settings.rb +28 -0
  18. data/lib/elasticsearch/api/actions/cluster/reroute.rb +44 -0
  19. data/lib/elasticsearch/api/actions/cluster/state.rb +47 -0
  20. data/lib/elasticsearch/api/actions/count.rb +46 -0
  21. data/lib/elasticsearch/api/actions/create.rb +34 -0
  22. data/lib/elasticsearch/api/actions/delete.rb +61 -0
  23. data/lib/elasticsearch/api/actions/delete_by_query.rb +62 -0
  24. data/lib/elasticsearch/api/actions/exists.rb +51 -0
  25. data/lib/elasticsearch/api/actions/explain.rb +71 -0
  26. data/lib/elasticsearch/api/actions/get.rb +59 -0
  27. data/lib/elasticsearch/api/actions/get_source.rb +59 -0
  28. data/lib/elasticsearch/api/actions/index.rb +81 -0
  29. data/lib/elasticsearch/api/actions/indices/analyze.rb +63 -0
  30. data/lib/elasticsearch/api/actions/indices/clear_cache.rb +69 -0
  31. data/lib/elasticsearch/api/actions/indices/close.rb +35 -0
  32. data/lib/elasticsearch/api/actions/indices/create.rb +83 -0
  33. data/lib/elasticsearch/api/actions/indices/delete.rb +48 -0
  34. data/lib/elasticsearch/api/actions/indices/delete_alias.rb +37 -0
  35. data/lib/elasticsearch/api/actions/indices/delete_mapping.rb +26 -0
  36. data/lib/elasticsearch/api/actions/indices/delete_template.rb +33 -0
  37. data/lib/elasticsearch/api/actions/indices/delete_warmer.rb +32 -0
  38. data/lib/elasticsearch/api/actions/indices/exists.rb +35 -0
  39. data/lib/elasticsearch/api/actions/indices/exists_alias.rb +41 -0
  40. data/lib/elasticsearch/api/actions/indices/exists_type.rb +39 -0
  41. data/lib/elasticsearch/api/actions/indices/flush.rb +40 -0
  42. data/lib/elasticsearch/api/actions/indices/get_alias.rb +41 -0
  43. data/lib/elasticsearch/api/actions/indices/get_aliases.rb +32 -0
  44. data/lib/elasticsearch/api/actions/indices/get_mapping.rb +36 -0
  45. data/lib/elasticsearch/api/actions/indices/get_settings.rb +32 -0
  46. data/lib/elasticsearch/api/actions/indices/get_template.rb +30 -0
  47. data/lib/elasticsearch/api/actions/indices/get_warmer.rb +44 -0
  48. data/lib/elasticsearch/api/actions/indices/open.rb +33 -0
  49. data/lib/elasticsearch/api/actions/indices/optimize.rb +57 -0
  50. data/lib/elasticsearch/api/actions/indices/put_alias.rb +43 -0
  51. data/lib/elasticsearch/api/actions/indices/put_mapping.rb +49 -0
  52. data/lib/elasticsearch/api/actions/indices/put_settings.rb +45 -0
  53. data/lib/elasticsearch/api/actions/indices/put_template.rb +40 -0
  54. data/lib/elasticsearch/api/actions/indices/put_warmer.rb +48 -0
  55. data/lib/elasticsearch/api/actions/indices/refresh.rb +43 -0
  56. data/lib/elasticsearch/api/actions/indices/segments.rb +33 -0
  57. data/lib/elasticsearch/api/actions/indices/snapshot_index.rb +32 -0
  58. data/lib/elasticsearch/api/actions/indices/stats.rb +96 -0
  59. data/lib/elasticsearch/api/actions/indices/status.rb +46 -0
  60. data/lib/elasticsearch/api/actions/indices/update_aliases.rb +49 -0
  61. data/lib/elasticsearch/api/actions/indices/validate_query.rb +68 -0
  62. data/lib/elasticsearch/api/actions/info.rb +19 -0
  63. data/lib/elasticsearch/api/actions/mget.rb +64 -0
  64. data/lib/elasticsearch/api/actions/mlt.rb +86 -0
  65. data/lib/elasticsearch/api/actions/msearch.rb +75 -0
  66. data/lib/elasticsearch/api/actions/percolate.rb +57 -0
  67. data/lib/elasticsearch/api/actions/ping.rb +29 -0
  68. data/lib/elasticsearch/api/actions/scroll.rb +44 -0
  69. data/lib/elasticsearch/api/actions/search.rb +145 -0
  70. data/lib/elasticsearch/api/actions/suggest.rb +46 -0
  71. data/lib/elasticsearch/api/actions/update.rb +103 -0
  72. data/lib/elasticsearch/api/namespace/cluster.rb +20 -0
  73. data/lib/elasticsearch/api/namespace/common.rb +27 -0
  74. data/lib/elasticsearch/api/namespace/indices.rb +20 -0
  75. data/lib/elasticsearch/api/utils.rb +97 -0
  76. data/lib/elasticsearch/api/version.rb +5 -0
  77. data/test/integration/yaml_test_runner.rb +330 -0
  78. data/test/test_helper.rb +52 -0
  79. data/test/unit/bulk_test.rb +85 -0
  80. data/test/unit/client_test.rb +31 -0
  81. data/test/unit/cluster/get_settings_test.rb +26 -0
  82. data/test/unit/cluster/health_test.rb +38 -0
  83. data/test/unit/cluster/node_hot_threads_test.rb +35 -0
  84. data/test/unit/cluster/node_info_test.rb +45 -0
  85. data/test/unit/cluster/node_shutdown_test.rb +45 -0
  86. data/test/unit/cluster/node_stats_test.rb +65 -0
  87. data/test/unit/cluster/put_settings_test.rb +26 -0
  88. data/test/unit/cluster/reroute_test.rb +38 -0
  89. data/test/unit/cluster/state_test.rb +37 -0
  90. data/test/unit/count_test.rb +46 -0
  91. data/test/unit/create_document_test.rb +38 -0
  92. data/test/unit/delete_by_query_test.rb +42 -0
  93. data/test/unit/delete_document_test.rb +62 -0
  94. data/test/unit/exists_document_test.rb +76 -0
  95. data/test/unit/explain_document_test.rb +64 -0
  96. data/test/unit/get_document_source_test.rb +62 -0
  97. data/test/unit/get_document_test.rb +62 -0
  98. data/test/unit/hashie_test.rb +78 -0
  99. data/test/unit/index_document_test.rb +77 -0
  100. data/test/unit/indices/analyze_test.rb +67 -0
  101. data/test/unit/indices/clear_cache_test.rb +45 -0
  102. data/test/unit/indices/close_test.rb +42 -0
  103. data/test/unit/indices/create_test.rb +42 -0
  104. data/test/unit/indices/delete_alias_test.rb +38 -0
  105. data/test/unit/indices/delete_mapping_test.rb +47 -0
  106. data/test/unit/indices/delete_template_test.rb +26 -0
  107. data/test/unit/indices/delete_test.rb +45 -0
  108. data/test/unit/indices/delete_warmer_test.rb +59 -0
  109. data/test/unit/indices/exists_alias_test.rb +65 -0
  110. data/test/unit/indices/exists_test.rb +57 -0
  111. data/test/unit/indices/exists_type_test.rb +59 -0
  112. data/test/unit/indices/flush_test.rb +45 -0
  113. data/test/unit/indices/get_alias_test.rb +41 -0
  114. data/test/unit/indices/get_aliases_test.rb +35 -0
  115. data/test/unit/indices/get_mapping_test.rb +53 -0
  116. data/test/unit/indices/get_settings_test.rb +35 -0
  117. data/test/unit/indices/get_template_test.rb +32 -0
  118. data/test/unit/indices/get_warmer_test.rb +41 -0
  119. data/test/unit/indices/open_test.rb +42 -0
  120. data/test/unit/indices/optimize_test.rb +45 -0
  121. data/test/unit/indices/put_alias_test.rb +47 -0
  122. data/test/unit/indices/put_mapping_test.rb +57 -0
  123. data/test/unit/indices/put_settings_test.rb +50 -0
  124. data/test/unit/indices/put_template_test.rb +48 -0
  125. data/test/unit/indices/put_warmer_test.rb +62 -0
  126. data/test/unit/indices/refresh_test.rb +55 -0
  127. data/test/unit/indices/segments_test.rb +55 -0
  128. data/test/unit/indices/snapshot_index_test.rb +55 -0
  129. data/test/unit/indices/stats_test.rb +76 -0
  130. data/test/unit/indices/status_test.rb +55 -0
  131. data/test/unit/indices/update_aliases_test.rb +42 -0
  132. data/test/unit/indices/validate_query_test.rb +75 -0
  133. data/test/unit/info_test.rb +26 -0
  134. data/test/unit/json_builders_test.rb +64 -0
  135. data/test/unit/mget_test.rb +70 -0
  136. data/test/unit/mlt_test.rb +80 -0
  137. data/test/unit/msearch_test.rb +120 -0
  138. data/test/unit/percolate_test.rb +49 -0
  139. data/test/unit/ping_test.rb +48 -0
  140. data/test/unit/scroll_test.rb +26 -0
  141. data/test/unit/search_test.rb +93 -0
  142. data/test/unit/suggest_test.rb +55 -0
  143. data/test/unit/update_document_test.rb +62 -0
  144. data/test/unit/utils_test.rb +118 -0
  145. metadata +498 -0
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class IndexDocumentTest < ::Test::Unit::TestCase
6
+
7
+ context "Creating a document with the #create method" do
8
+ subject { FakeClient.new }
9
+
10
+ should "perform the create request" do
11
+ subject.expects(:perform_request).with do |method, url, params, body|
12
+ assert_equal 'POST', method
13
+ assert_equal 'foo/bar', url
14
+ assert_equal({:op_type => 'create'}, params)
15
+ assert_equal({:foo => 'bar'}, body)
16
+ true
17
+ end.returns(FakeResponse.new)
18
+
19
+ subject.create :index => 'foo', :type => 'bar', :body => {:foo => 'bar'}
20
+ end
21
+
22
+ should "perform the create request with a specific ID" do
23
+ subject.expects(:perform_request).with do |method, url, params, body|
24
+ assert_equal 'PUT', method
25
+ assert_equal 'foo/bar/123', url
26
+ assert_equal 'create', params[:op_type]
27
+ assert_nil params[:id]
28
+ assert_equal({:foo => 'bar'}, body)
29
+ true
30
+ end.returns(FakeResponse.new)
31
+
32
+ subject.create :index => 'foo', :type => 'bar', :id => '123', :body => {:foo => 'bar'}
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class DeleteByQueryTest < ::Test::Unit::TestCase
6
+
7
+ context "Delete by query" do
8
+ subject { FakeClient.new }
9
+
10
+ should "require the :index argument" do
11
+ assert_raise ArgumentError do
12
+ subject.delete_by_query :body => {}
13
+ end
14
+ end
15
+
16
+ should "perform correct request" do
17
+ subject.expects(:perform_request).with do |method, url, params, body|
18
+ assert_equal 'DELETE', method
19
+ assert_equal 'foo/_query', url
20
+ assert_equal Hash.new, params
21
+ assert_equal Hash.new, body[:term]
22
+ true
23
+ end.returns(FakeResponse.new)
24
+
25
+ subject.delete_by_query :index => 'foo', :body => { :term => {} }
26
+ end
27
+
28
+ should "pass the query in URL parameters" do
29
+ subject.expects(:perform_request).with do |method, url, params, body|
30
+ assert_equal 'foo/_query', url
31
+ assert_equal 'foo:bar', params[:q]
32
+ true
33
+ end.returns(FakeResponse.new)
34
+
35
+ subject.delete_by_query :index => 'foo', :q => 'foo:bar'
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,62 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class DeleteTest < ::Test::Unit::TestCase
6
+
7
+ context "Delete document" do
8
+ subject { FakeClient.new }
9
+
10
+ should "require the :index argument" do
11
+ assert_raise ArgumentError do
12
+ subject.delete :type => 'bar', :id => '1'
13
+ end
14
+ end
15
+
16
+ should "require the :type argument" do
17
+ assert_raise ArgumentError do
18
+ subject.delete :index => 'foo', :id => '1'
19
+ end
20
+ end
21
+
22
+ should "require the :id argument" do
23
+ assert_raise ArgumentError do
24
+ subject.delete :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 'DELETE', method
31
+ assert_equal 'foo/bar/1', url
32
+ assert_equal Hash.new, params
33
+ assert_nil body
34
+ true
35
+ end.returns(FakeResponse.new)
36
+
37
+ subject.delete :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', url
43
+ assert_equal 'abc123', params[:routing]
44
+ true
45
+ end.returns(FakeResponse.new)
46
+
47
+ subject.delete :index => 'foo', :type => 'bar', :id => '1', :routing => 'abc123'
48
+ end
49
+
50
+ should "catch a NotFound exception with the ignore parameter" do
51
+ subject.expects(:perform_request).raises(NotFound)
52
+
53
+ assert_nothing_raised do
54
+ subject.get :index => 'foo', :type => 'bar', :id => 'XXX', ignore: 404
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,76 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class ExistsTest < ::Test::Unit::TestCase
6
+
7
+ context "Exists document" do
8
+ subject { FakeClient.new }
9
+
10
+ should "require the :index argument" do
11
+ assert_raise ArgumentError do
12
+ subject.exists :type => 'bar', :id => '1'
13
+ end
14
+ end
15
+
16
+ should "NOT require the :type argument" do
17
+ assert_nothing_raised do
18
+ subject.exists :index => 'foo', :id => '1'
19
+ end
20
+ end
21
+
22
+ should "require the :id argument" do
23
+ assert_raise ArgumentError do
24
+ subject.exists :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 'HEAD', method
31
+ assert_equal 'foo/bar/1', url
32
+ assert_equal Hash.new, params
33
+ assert_nil body
34
+ true
35
+ end.returns(FakeResponse.new)
36
+
37
+ subject.exists :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', url
43
+ assert_equal 'abc123', params[:routing]
44
+ true
45
+ end.returns(FakeResponse.new)
46
+
47
+ subject.exists :index => 'foo', :type => 'bar', :id => '1', :routing => 'abc123'
48
+ end
49
+
50
+ should "return true for successful response" do
51
+ subject.expects(:perform_request).returns(FakeResponse.new 200, 'OK')
52
+ assert_equal true, subject.exists(:index => 'foo', :type => 'bar', :id => '1')
53
+ end
54
+
55
+ should "return false for 404 response" do
56
+ subject.expects(:perform_request).returns(FakeResponse.new 404, 'Not Found')
57
+ assert_equal false, subject.exists(:index => 'foo', :type => 'bar', :id => '1')
58
+ end
59
+
60
+ should "return false on 'not found' exceptions" do
61
+ subject.expects(:perform_request).raises(StandardError.new '404 NotFound')
62
+ assert_equal false, subject.exists(:index => 'foo', :type => 'bar', :id => '1')
63
+ end
64
+
65
+ should "re-raise generic exceptions" do
66
+ subject.expects(:perform_request).raises(StandardError)
67
+ assert_raise(StandardError) do
68
+ assert_equal false, subject.exists(:index => 'foo', :type => 'bar', :id => '1')
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,64 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class ExplainTest < ::Test::Unit::TestCase
6
+
7
+ context "Explain document" do
8
+ subject { FakeClient.new }
9
+
10
+ should "require the :index argument" do
11
+ assert_raise ArgumentError do
12
+ subject.explain :type => 'bar', :id => '1'
13
+ end
14
+ end
15
+
16
+ should "require the :type argument" do
17
+ assert_raise ArgumentError do
18
+ subject.explain :index => 'foo', :id => '1'
19
+ end
20
+ end
21
+
22
+ should "require the :id argument" do
23
+ assert_raise ArgumentError do
24
+ subject.explain :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/_explain', url
32
+ assert_equal Hash.new, params
33
+ assert_equal Hash.new, body
34
+ true
35
+ end.returns(FakeResponse.new)
36
+
37
+ subject.explain :index => 'foo', :type => 'bar', :id => 1, :body => {}
38
+ end
39
+
40
+ should "pass the query in URL parameters" do
41
+ subject.expects(:perform_request).with do |method, url, params, body|
42
+ assert_equal 'foo/bar/1/_explain', url
43
+ assert_equal 'foo', params[:q]
44
+ true
45
+ end.returns(FakeResponse.new)
46
+
47
+ subject.explain :index => 'foo', :type => 'bar', :id => 1, :q => 'foo'
48
+ end
49
+
50
+ should "pass the request definition in the body" do
51
+ subject.expects(:perform_request).with do |method, url, params, body|
52
+ assert_equal 'foo/bar/1/_explain', url
53
+ assert_equal Hash.new, body[:query][:match]
54
+ true
55
+ end.returns(FakeResponse.new)
56
+
57
+ subject.explain :index => 'foo', :type => 'bar', :id => 1, :body => { :query => { :match => {} } }
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,62 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class GetSourceTest < ::Test::Unit::TestCase
6
+
7
+ context "Get document source" do
8
+ subject { FakeClient.new }
9
+
10
+ should "require the :index argument" do
11
+ assert_raise ArgumentError do
12
+ subject.get_source :type => 'bar', :id => '1'
13
+ end
14
+ end
15
+
16
+ should "NOT require the :type argument" do
17
+ assert_nothing_raised do
18
+ subject.get_source :index => 'foo', :id => '1'
19
+ end
20
+ end
21
+
22
+ should "require the :id argument" do
23
+ assert_raise ArgumentError do
24
+ subject.get_source :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/_source', url
32
+ assert_equal Hash.new, params
33
+ assert_nil body
34
+ true
35
+ end.returns(FakeResponse.new)
36
+
37
+ subject.get_source :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/_source', url
43
+ assert_equal 'abc123', params[:routing]
44
+ true
45
+ end.returns(FakeResponse.new)
46
+
47
+ subject.get_source :index => 'foo', :type => 'bar', :id => '1', :routing => 'abc123'
48
+ end
49
+
50
+ should "catch a NotFound exception with the ignore parameter" do
51
+ subject.expects(:perform_request).raises(NotFound)
52
+
53
+ assert_nothing_raised do
54
+ subject.get :index => 'foo', :type => 'bar', :id => 'XXX', ignore: 404
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,62 @@
1
+ require 'test_helper'
2
+
3
+ module Elasticsearch
4
+ module Test
5
+ class GetTest < ::Test::Unit::TestCase
6
+
7
+ context "Get document" do
8
+ subject { FakeClient.new }
9
+
10
+ should "require the :index argument" do
11
+ assert_raise ArgumentError do
12
+ subject.get :type => 'bar', :id => '1'
13
+ end
14
+ end
15
+
16
+ should "NOT require the :type argument" do
17
+ assert_nothing_raised do
18
+ subject.get :index => 'foo', :id => '1'
19
+ end
20
+ end
21
+
22
+ should "require the :id argument" do
23
+ assert_raise ArgumentError do
24
+ subject.get :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', url
32
+ assert_equal Hash.new, params
33
+ assert_nil body
34
+ true
35
+ end.returns(FakeResponse.new)
36
+
37
+ subject.get :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', url
43
+ assert_equal 'abc123', params[:routing]
44
+ true
45
+ end.returns(FakeResponse.new)
46
+
47
+ subject.get :index => 'foo', :type => 'bar', :id => '1', :routing => 'abc123'
48
+ end
49
+
50
+ should "catch a NotFound exception with the ignore parameter" do
51
+ subject.expects(:perform_request).raises(NotFound)
52
+
53
+ assert_nothing_raised do
54
+ subject.get :index => 'foo', :type => 'bar', :id => 'XXX', ignore: 404
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,78 @@
1
+ require 'test_helper'
2
+
3
+ require 'hashie'
4
+
5
+ module Elasticsearch
6
+ module Test
7
+ class HashieTest < ::Test::Unit::TestCase
8
+
9
+ context "Hashie" do
10
+ subject { FakeClient.new }
11
+
12
+ should "wrap the response" do
13
+ json =<<-JSON
14
+ {
15
+ "took": 14,
16
+ "timed_out": false,
17
+ "_shards": {
18
+ "total": 1,
19
+ "successful": 1,
20
+ "failed": 0
21
+ },
22
+ "hits": {
23
+ "total": 5,
24
+ "max_score": 0.51104903,
25
+ "hits": [
26
+ {
27
+ "_index": "myindex",
28
+ "_type": "mytype",
29
+ "_id": "1",
30
+ "_score": 0.51104903,
31
+ "_source": {
32
+ "title": "Test 1",
33
+ "tags": [
34
+ "y",
35
+ "z"
36
+ ],
37
+ "published": true,
38
+ "published_at": "2013-06-22T21:13:00Z",
39
+ "counter": 1
40
+ }
41
+ }
42
+ ]
43
+ },
44
+ "facets": {
45
+ "tags": {
46
+ "_type": "terms",
47
+ "missing": 0,
48
+ "total": 10,
49
+ "other": 0,
50
+ "terms": [
51
+ {
52
+ "term": "z",
53
+ "count": 4
54
+ },
55
+ {
56
+ "term": "y",
57
+ "count": 3
58
+ },
59
+ {
60
+ "term": "x",
61
+ "count": 3
62
+ }
63
+ ]
64
+ }
65
+ }
66
+ }
67
+ JSON
68
+
69
+ response = Hashie::Mash.new MultiJson.load(json)
70
+
71
+ assert_equal 'Test 1', response.hits.hits.first._source.title
72
+ assert_equal 'z', response.facets.tags.terms.first.term
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ end