elasticsearch-api 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 247c30ecf7755b5a5d22ce3c300937ef7c177e94
4
+ data.tar.gz: 88f090eda370aa8f3abe42fc23e662cb97e5543b
5
+ SHA512:
6
+ metadata.gz: 080f1aeb5a2c3e8ab6db4b0ef19dbf3fea7c4a6d5ad06298cb04d1210088fbc4d45248bd4e8be64b00c66817ad72a5f326fbd2218afb254dae7fd08b85009540
7
+ data.tar.gz: 442f18f9075381f6a7fe5c3ad6b8f07c952396c36e22d57c73be6df0a5b110935bfe295bb444dc997081a6d8ce76bee0135e592bbc60bda5238c5ab93f36f323
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in elasticsearch-api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2013 Elasticsearch
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # Elasticsearch::API
2
+
3
+ **This library is part of the [`elasticsearch-ruby`](https://github.com/elasticsearch/elasticsearch-ruby/) package;
4
+ please refer to it, unless you want to use this library standalone.**
5
+
6
+ ----
7
+
8
+ The `elasticsearch-api` library provides a Ruby implementation of
9
+ the [Elasticsearch](http://elasticsearch.org) REST API.
10
+
11
+ It does not provide an Elasticsearch client; see the
12
+ [`elasticsearch-transport`](https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-transport)
13
+ library.
14
+
15
+ The library is compatible with Ruby 1.8.7 or higher.
16
+
17
+ ## Installation
18
+
19
+ Install the package from [Rubygems](https://rubygems.org):
20
+
21
+ gem install elasticsearch-api
22
+
23
+ To use an unreleased version, either add it to your `Gemfile` for [Bundler](http://gembundler.com):
24
+
25
+ gem 'elasticsearch-api', git: 'git://github.com/elasticsearch/elasticsearch-ruby.git'
26
+
27
+ or install it from a source code checkout:
28
+
29
+ git clone https://github.com/elasticsearch/elasticsearch-ruby.git
30
+ cd elasticsearch-ruby/elasticsearch-api
31
+ bundle install
32
+ rake install
33
+
34
+ ## Usage
35
+
36
+ The library is designed as a group of standalone Ruby modules, which can be mixed into a class
37
+ providing connection to Elasticsearch -- an Elasticsearch client.
38
+
39
+ **When you use the client from the [`elasticsearch-ruby`](https://github.com/elasticsearch/elasticsearch-ruby/) package,
40
+ the library modules have been already included**, so you just call the API methods:
41
+
42
+ ```ruby
43
+ require 'elasticsearch'
44
+
45
+ client = Elasticsearch::Client.new log: true
46
+
47
+ client.index index: 'myindex', type: 'mytype', id: 1, body: { title: 'Test' }
48
+ # => {"ok"=>true, "_index"=>"myindex", ...}
49
+
50
+ client.search body: { query: { match: { title: 'test' } } }
51
+ # => {"took"=>2, ..., "hits"=>{"total":5, ...}}
52
+ ```
53
+
54
+ When you want to mix the library into you own client, it must conform to a following _contract_:
55
+
56
+ * It responds to a `perform_request(method, path, params, body)` method,
57
+ * the method returns an object with `status`, `body` and `headers` methods.
58
+
59
+ A simple client could look like this:
60
+
61
+ ```ruby
62
+ require 'multi_json'
63
+ require 'faraday'
64
+ require 'elasticsearch/api'
65
+
66
+ class MySimpleClient
67
+ include Elasticsearch::API
68
+
69
+ CONNECTION = ::Faraday::Connection.new url: 'http://localhost:9200'
70
+
71
+ def perform_request(method, path, params, body)
72
+ puts "--> #{method.upcase} #{path} #{params} #{body}"
73
+
74
+ CONNECTION.run_request \
75
+ method.downcase.to_sym,
76
+ path,
77
+ ( body ? MultiJson.dump(body): nil ),
78
+ {'Content-Type' => 'application/json'}
79
+ end
80
+ end
81
+
82
+ client = MySimpleClient.new
83
+
84
+ p client.cluster.health
85
+ # --> GET _cluster/health {}
86
+ # => "{"cluster_name":"elasticsearch" ... }"
87
+
88
+ p client.index index: 'myindex', type: 'mytype', id: 'custom', body: { title: "Indexing from my client" }
89
+ # --> PUT myindex/mytype/custom {} {:title=>"Indexing from my client"}
90
+ # => "{"ok":true, ... }"
91
+ ```
92
+
93
+ ## Using JSON Builders
94
+
95
+ Instead of passing the `:body` argument as a Ruby _Hash_, you can pass it as a _String_, potentially
96
+ taking advantage of JSON builders such as [JBuilder](https://github.com/rails/jbuilder) or
97
+ [Jsonify](https://github.com/bsiggelkow/jsonify):
98
+
99
+ ```ruby
100
+ require 'jbuilder'
101
+
102
+ json = Jbuilder.encode do |json|
103
+ json.query do
104
+ json.match do
105
+ json.title do
106
+ json.query 'test 1'
107
+ json.operator 'and'
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ client.search index: 'myindex', body: json
114
+
115
+ # 2013-06-25 09:56:05 +0200: GET http://localhost:9200/myindex/_search [status:200, request:0.015s, query:0.011s]
116
+ # 2013-06-25 09:56:05 +0200: > {"query":{"match":{"title":{"query":"test 1","operator":"and"}}}}
117
+ # ...
118
+ # => {"took"=>21, ..., "hits"=>{"total"=>1, "hits"=>[{ "_source"=>{"title"=>"Test 1", ...}}]}}
119
+ ```
120
+
121
+ ## Using Hash Wrappers
122
+
123
+ For a more comfortable access to response properties, you may wrap it in one of the _Hash_ "object access"
124
+ wrappers, such as [`Hashie::Mash`](https://github.com/intridea/hashie):
125
+
126
+ ```ruby
127
+ require 'hashie'
128
+
129
+ response = client.search index: 'myindex',
130
+ body: {
131
+ query: { match: { title: 'test' } },
132
+ facets: { tags: { terms: { field: 'tags' } } }
133
+ }
134
+
135
+ mash = Hashie::Mash.new response
136
+
137
+ mash.hits.hits.first._source.title
138
+ # => 'Test'
139
+
140
+ response.facets.tags.terms.first
141
+ # => #<Hashie::Mash count=3 term="z">
142
+ ```
143
+
144
+ ## License
145
+
146
+ This software is licensed under the Apache 2 license, quoted below.
147
+
148
+ Copyright (c) 2013 Elasticsearch <http://www.elasticsearch.org>
149
+
150
+ Licensed under the Apache License, Version 2.0 (the "License");
151
+ you may not use this file except in compliance with the License.
152
+ You may obtain a copy of the License at
153
+
154
+ http://www.apache.org/licenses/LICENSE-2.0
155
+
156
+ Unless required by applicable law or agreed to in writing, software
157
+ distributed under the License is distributed on an "AS IS" BASIS,
158
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159
+ See the License for the specific language governing permissions and
160
+ limitations under the License.
data/Rakefile ADDED
@@ -0,0 +1,62 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Run unit tests"
4
+ task :default => 'test:unit'
5
+ task :test => 'test:unit'
6
+
7
+ # ----- Test tasks ------------------------------------------------------------
8
+
9
+ require 'rake/testtask'
10
+ namespace :test do
11
+ Rake::TestTask.new(:unit) do |test|
12
+ test.libs << 'lib' << 'test'
13
+ test.test_files = FileList["test/unit/**/*_test.rb"]
14
+ # test.verbose = true
15
+ # test.warning = true
16
+ end
17
+
18
+ Rake::TestTask.new(:integration) do |test|
19
+ test.libs << 'lib' << 'test'
20
+ test.test_files = FileList["test/integration/yaml_test_runner.rb", "test/integration/**/*_test.rb"]
21
+ end
22
+
23
+ Rake::TestTask.new(:all) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.test_files = FileList["test/unit/**/*_test.rb", "test/integration/**/*_test.rb"]
26
+ end
27
+
28
+ namespace :server do
29
+ desc "Start Elasticsearch nodes for tests"
30
+ task :start do
31
+ $LOAD_PATH << File.expand_path('../../elasticsearch-transport/lib', __FILE__) << File.expand_path('../test', __FILE__)
32
+ require 'elasticsearch/transport'
33
+ require 'elasticsearch/transport/extensions/test_cluster'
34
+ Elasticsearch::TestCluster.start
35
+ end
36
+
37
+ desc "Stop Elasticsearch nodes for tests"
38
+ task :stop do
39
+ $LOAD_PATH << File.expand_path('../../elasticsearch-transport/lib', __FILE__) << File.expand_path('../test', __FILE__)
40
+ require 'elasticsearch/transport'
41
+ require 'elasticsearch/transport/extensions/test_cluster'
42
+ Elasticsearch::TestCluster.stop
43
+ end
44
+ end
45
+ end
46
+
47
+ # ----- Documentation tasks ---------------------------------------------------
48
+
49
+ require 'yard'
50
+ YARD::Rake::YardocTask.new(:doc) do |t|
51
+ t.options = %w| --embed-mixins --markup=markdown |
52
+ end
53
+
54
+ # ----- Code analysis tasks ---------------------------------------------------
55
+
56
+ if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
57
+ require 'cane/rake_task'
58
+ Cane::RakeTask.new(:quality) do |cane|
59
+ cane.abc_max = 15
60
+ cane.no_style = true
61
+ end
62
+ end
@@ -0,0 +1,51 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'elasticsearch/api/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "elasticsearch-api"
8
+ s.version = Elasticsearch::API::VERSION
9
+ s.authors = ["Karel Minarik"]
10
+ s.email = ["karel.minarik@elasticsearch.org"]
11
+ s.summary = "Ruby API for Elasticsearch."
12
+ s.homepage = "https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-api"
13
+ s.license = "Apache 2"
14
+
15
+ s.files = `git ls-files`.split($/)
16
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.require_paths = ["lib"]
19
+
20
+ s.extra_rdoc_files = [ "README.md", "LICENSE.txt" ]
21
+ s.rdoc_options = [ "--charset=UTF-8" ]
22
+
23
+ s.add_dependency "multi_json"
24
+
25
+ s.add_development_dependency "bundler", "> 1"
26
+ s.add_development_dependency "rake"
27
+
28
+ s.add_development_dependency "elasticsearch-transport"
29
+
30
+ s.add_development_dependency "ansi"
31
+ s.add_development_dependency "shoulda-context"
32
+ s.add_development_dependency "mocha"
33
+ s.add_development_dependency "turn"
34
+ s.add_development_dependency "yard"
35
+ s.add_development_dependency "ruby-prof"
36
+
37
+ s.add_development_dependency "multi_json"
38
+ s.add_development_dependency "jbuilder"
39
+ s.add_development_dependency "jsonify"
40
+ s.add_development_dependency "hashie"
41
+
42
+ if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
43
+ s.add_development_dependency "simplecov"
44
+ s.add_development_dependency "cane"
45
+ s.add_development_dependency "require-prof"
46
+ end
47
+
48
+ s.description = <<-DESC.gsub(/^ /, '')
49
+ Ruby API for Elasticsearch. See the `elasticsearch` gem for full integration.
50
+ DESC
51
+ end
@@ -0,0 +1 @@
1
+ require 'elasticsearch/api'
@@ -0,0 +1,23 @@
1
+ require "multi_json"
2
+
3
+ require "elasticsearch/api/version"
4
+ require "elasticsearch/api/namespace/common"
5
+ require "elasticsearch/api/utils"
6
+
7
+ Dir[ File.expand_path('../api/actions/**/*.rb', __FILE__) ].each { |f| require f }
8
+ Dir[ File.expand_path('../api/namespace/**/*.rb', __FILE__) ].each { |f| require f }
9
+
10
+ module Elasticsearch
11
+ module API
12
+
13
+ # Auto-include all namespaces in the receiver
14
+ #
15
+ def self.included(base)
16
+ base.send :include,
17
+ Elasticsearch::API::Common,
18
+ Elasticsearch::API::Actions,
19
+ Elasticsearch::API::Cluster,
20
+ Elasticsearch::API::Indices
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,71 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Actions
4
+
5
+ # Perform multiple index, delete or update operations in a single request.
6
+ #
7
+ # Pass the operations in the `:body` option as an array of hashes, following Elasticsearch conventions.
8
+ # For operations which take data, pass them as the `:data` option in the operation hash.
9
+ #
10
+ # @example Perform three operations in a single request
11
+ #
12
+ # client.bulk body: [
13
+ # { index: { _index: 'myindex', _type: 'mytype', _id: 1, data: { title: 'foo' } } },
14
+ # { update: { _index: 'myindex', _type: 'mytype', _id: 2, data: { doc: { title: 'foo' } } } },
15
+ # { delete: { _index: 'myindex', _type: 'mytype', _id: 3 },
16
+ # ]
17
+ #
18
+ # @example Perform a script-based bulk update
19
+ #
20
+ # client.bulk body: [
21
+ # { update: { _index: 'myindex', _type: 'mytype', _id: 1,
22
+ # data: {
23
+ # script: "ctx._source.counter += value",
24
+ # lang: 'js',
25
+ # params: { value: 1 }, upsert: { counter: 0 } }
26
+ # }},
27
+ # { update: { _index: 'myindex', _type: 'mytype', _id: 2,
28
+ # data: {
29
+ # script: "ctx._source.counter += value",
30
+ # lang: 'js',
31
+ # params: { value: 42 }, upsert: { counter: 0 } }
32
+ # }}
33
+ #
34
+ # ]
35
+ #
36
+ # @option arguments [String] :index Default index for items which don't provide one
37
+ # @option arguments [String] :type Default document type for items which don't provide one
38
+ # @option arguments [Array<Hash>] :body An array of operations to perform, each operation is a Hash
39
+ # @option arguments [String] :consistency Explicit write consistency setting for the operation (options: one, quorum, all)
40
+ # @option arguments [Boolean] :refresh Refresh the index after performing the operation
41
+ # @option arguments [String] :replication Explicitely set the replication type (options: sync, async)
42
+ # @option arguments [String] :type Default document type for items which don't provide one
43
+ #
44
+ # @return [Hash] Deserialized Elasticsearch response
45
+ #
46
+ # @see http://elasticsearch.org/guide/reference/api/bulk/
47
+ #
48
+ def bulk(arguments={})
49
+ method = 'POST'
50
+ path = [arguments[:index], arguments[:type], '_bulk'].compact.join('/')
51
+ params = arguments.select do |k,v|
52
+ [ :consistency,
53
+ :refresh,
54
+ :replication,
55
+ :type ].include?(k)
56
+ end
57
+ # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
58
+ params = Hash[params] unless params.is_a?(Hash)
59
+ body = arguments[:body]
60
+
61
+ if body.is_a? Array
62
+ payload = Utils.__bulkify(body)
63
+ else
64
+ payload = body
65
+ end
66
+
67
+ perform_request(method, path, params, payload).body
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,21 @@
1
+ module Elasticsearch
2
+ module API
3
+ module Cluster
4
+ module Actions
5
+
6
+ # Get the cluster settings (previously set with {Cluster::Actions#put_settings})
7
+ #
8
+ # @see http://elasticsearch.org/guide/reference/api/admin-cluster-update-settings/
9
+ #
10
+ def get_settings(arguments={})
11
+ method = 'GET'
12
+ path = "_cluster/settings"
13
+ params = {}
14
+ body = nil
15
+
16
+ perform_request(method, path, params, body).body
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end