opensearch-api 2.0.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +28 -0
  5. data/Gemfile +2 -2
  6. data/README.md +12 -182
  7. data/Rakefile +5 -5
  8. data/USER_GUIDE.md +155 -0
  9. data/lib/opensearch/api/actions/cat/all_pit_segments.rb +46 -0
  10. data/lib/opensearch/api/actions/cat/allocation.rb +4 -2
  11. data/lib/opensearch/api/actions/cat/cluster_manager.rb +54 -0
  12. data/lib/opensearch/api/actions/cat/indices.rb +4 -2
  13. data/lib/opensearch/api/actions/cat/master.rb +3 -1
  14. data/lib/opensearch/api/actions/cat/nodeattrs.rb +4 -2
  15. data/lib/opensearch/api/actions/cat/nodes.rb +4 -2
  16. data/lib/opensearch/api/actions/cat/pending_tasks.rb +4 -2
  17. data/lib/opensearch/api/actions/cat/pit_segments.rb +49 -0
  18. data/lib/opensearch/api/actions/cat/plugins.rb +4 -2
  19. data/lib/opensearch/api/actions/cat/repositories.rb +4 -2
  20. data/lib/opensearch/api/actions/cat/shards.rb +4 -2
  21. data/lib/opensearch/api/actions/cat/snapshots.rb +3 -1
  22. data/lib/opensearch/api/actions/cat/templates.rb +4 -2
  23. data/lib/opensearch/api/actions/cat/thread_pool.rb +4 -2
  24. data/lib/opensearch/api/actions/cluster/delete_component_template.rb +4 -2
  25. data/lib/opensearch/api/actions/cluster/exists_component_template.rb +4 -2
  26. data/lib/opensearch/api/actions/cluster/get_component_template.rb +4 -2
  27. data/lib/opensearch/api/actions/cluster/get_settings.rb +3 -1
  28. data/lib/opensearch/api/actions/cluster/health.rb +4 -2
  29. data/lib/opensearch/api/actions/cluster/pending_tasks.rb +5 -3
  30. data/lib/opensearch/api/actions/cluster/put_component_template.rb +4 -2
  31. data/lib/opensearch/api/actions/cluster/put_settings.rb +3 -1
  32. data/lib/opensearch/api/actions/cluster/reroute.rb +4 -2
  33. data/lib/opensearch/api/actions/cluster/state.rb +4 -2
  34. data/lib/opensearch/api/actions/create_pit.rb +45 -0
  35. data/lib/opensearch/api/actions/dangling_indices/delete_dangling_index.rb +4 -2
  36. data/lib/opensearch/api/actions/dangling_indices/import_dangling_index.rb +4 -2
  37. data/lib/opensearch/api/actions/delete_all_pits.rb +26 -0
  38. data/lib/opensearch/api/actions/delete_pit.rb +30 -0
  39. data/lib/opensearch/api/actions/delete_script.rb +4 -2
  40. data/lib/opensearch/api/actions/features/get_features.rb +4 -2
  41. data/lib/opensearch/api/actions/get_all_pits.rb +26 -0
  42. data/lib/opensearch/api/actions/get_script.rb +4 -2
  43. data/lib/opensearch/api/actions/indices/add_block.rb +3 -1
  44. data/lib/opensearch/api/actions/indices/clone.rb +3 -1
  45. data/lib/opensearch/api/actions/indices/close.rb +3 -1
  46. data/lib/opensearch/api/actions/indices/create.rb +4 -2
  47. data/lib/opensearch/api/actions/indices/delete.rb +3 -1
  48. data/lib/opensearch/api/actions/indices/delete_alias.rb +4 -2
  49. data/lib/opensearch/api/actions/indices/delete_index_template.rb +4 -2
  50. data/lib/opensearch/api/actions/indices/delete_template.rb +4 -2
  51. data/lib/opensearch/api/actions/indices/exists_index_template.rb +4 -2
  52. data/lib/opensearch/api/actions/indices/exists_template.rb +4 -2
  53. data/lib/opensearch/api/actions/indices/get.rb +4 -2
  54. data/lib/opensearch/api/actions/indices/get_index_template.rb +4 -2
  55. data/lib/opensearch/api/actions/indices/get_mapping.rb +4 -2
  56. data/lib/opensearch/api/actions/indices/get_settings.rb +3 -1
  57. data/lib/opensearch/api/actions/indices/get_template.rb +4 -2
  58. data/lib/opensearch/api/actions/indices/open.rb +3 -1
  59. data/lib/opensearch/api/actions/indices/put_alias.rb +4 -2
  60. data/lib/opensearch/api/actions/indices/put_index_template.rb +4 -2
  61. data/lib/opensearch/api/actions/indices/put_mapping.rb +3 -1
  62. data/lib/opensearch/api/actions/indices/put_settings.rb +3 -1
  63. data/lib/opensearch/api/actions/indices/put_template.rb +4 -2
  64. data/lib/opensearch/api/actions/indices/rollover.rb +3 -1
  65. data/lib/opensearch/api/actions/indices/shrink.rb +3 -1
  66. data/lib/opensearch/api/actions/indices/simulate_index_template.rb +4 -2
  67. data/lib/opensearch/api/actions/indices/simulate_template.rb +4 -2
  68. data/lib/opensearch/api/actions/indices/split.rb +3 -1
  69. data/lib/opensearch/api/actions/indices/update_aliases.rb +4 -2
  70. data/lib/opensearch/api/actions/ingest/delete_pipeline.rb +3 -1
  71. data/lib/opensearch/api/actions/ingest/get_pipeline.rb +4 -2
  72. data/lib/opensearch/api/actions/ingest/put_pipeline.rb +3 -1
  73. data/lib/opensearch/api/actions/put_script.rb +3 -1
  74. data/lib/opensearch/api/actions/search_shards.rb +1 -1
  75. data/lib/opensearch/api/actions/snapshot/cleanup_repository.rb +3 -1
  76. data/lib/opensearch/api/actions/snapshot/clone.rb +4 -2
  77. data/lib/opensearch/api/actions/snapshot/create.rb +3 -1
  78. data/lib/opensearch/api/actions/snapshot/create_repository.rb +3 -1
  79. data/lib/opensearch/api/actions/snapshot/delete.rb +4 -2
  80. data/lib/opensearch/api/actions/snapshot/delete_repository.rb +3 -1
  81. data/lib/opensearch/api/actions/snapshot/get.rb +3 -1
  82. data/lib/opensearch/api/actions/snapshot/get_features.rb +4 -2
  83. data/lib/opensearch/api/actions/snapshot/get_repository.rb +3 -2
  84. data/lib/opensearch/api/actions/snapshot/restore.rb +3 -1
  85. data/lib/opensearch/api/actions/snapshot/status.rb +3 -1
  86. data/lib/opensearch/api/actions/snapshot/verify_repository.rb +3 -1
  87. data/lib/opensearch/api/utils.rb +4 -4
  88. data/lib/opensearch/api/version.rb +1 -1
  89. data/opensearch-api.gemspec +2 -2
  90. data/spec/opensearch/api/actions/cat/all_pit_segments_spec.rb +36 -0
  91. data/spec/opensearch/api/actions/cat/allocation_spec.rb +6 -7
  92. data/spec/opensearch/api/actions/cat/cluster_manager_spec.rb +26 -0
  93. data/spec/opensearch/api/actions/cat/pit_segments_spec.rb +43 -0
  94. data/spec/opensearch/api/actions/create_pit_spec.rb +58 -0
  95. data/spec/opensearch/api/actions/delete_all_pits_spec.rb +35 -0
  96. data/spec/opensearch/api/actions/delete_pit_spec.rb +41 -0
  97. data/spec/opensearch/api/actions/get_all_pits_spec.rb +35 -0
  98. data/spec/opensearch/api/actions/get_script_spec.rb +2 -2
  99. data/spec/opensearch/api/actions/hashie_spec.rb +0 -2
  100. data/spec/opensearch/api/actions/indices/clone_spec.rb +2 -2
  101. data/spec/opensearch/api/utils_spec.rb +6 -6
  102. data.tar.gz.sig +1 -1
  103. metadata +40 -23
  104. metadata.gz.sig +0 -0
  105. data/lib/opensearch/api/actions/close_point_in_time.rb +0 -50
  106. data/lib/opensearch/api/actions/open_point_in_time.rb +0 -72
  107. data/spec/opensearch/api/actions/close_point_in_time_spec.rb +0 -43
  108. data/spec/opensearch/api/actions/open_point_in_time_spec.rb +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51853db273e9ec1c68dcbc6a9e0f47dec778abf7b3983ff406d45ab2c7a8c6a4
4
- data.tar.gz: ec3001aa95a793ebe2473b4991cf1b203164627f51fa0bf0317e3b64de6ee92e
3
+ metadata.gz: 832f3792a1ba90a36107ed481ce4a8d312788f0cc6d2499010fbb83f75310b3f
4
+ data.tar.gz: 8cd92be697d977c3e7dbb8e968f89c5e65c72d8780b825db470ae902a0a8fa4e
5
5
  SHA512:
6
- metadata.gz: 894cc99cd81a9a9e5d3a3960ac3856de63e34efc4798286eb4aa99faff06c68d43974ca53e3f176efa3671c1a7575fbcde67bfff4acdf1f0d657d6135e906763
7
- data.tar.gz: d9eaab4e5888fec4f1b11686b90d8141f04d5a03b7cc0e0688ea0691c0d7b5b643082059c3fec2d35bc20874e282ad3cbab83e26c1d8c8e6a7e2af641213e666
6
+ metadata.gz: 9af645120326fb0d4a4b3afe5dd063356c54eb02b4a813c2d3a86a6ffa4add32ec7c31291ade794d1fa4a229a6294d0882b58b92310746a783d170bd07c5147e
7
+ data.tar.gz: 65efd59ac74703fd6d6daf9ff04744e46cd962111821a6d9ede0653308c4563aa9171b0d6afb36e050e33a0bc56b8aff78358a1311d0743a1701ff661cfedc99
checksums.yaml.gz.sig CHANGED
Binary file
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .ruby-version
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
data/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # CHANGELOG
2
+ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3
+
4
+ ## [Unreleased]
5
+ ### Added
6
+ ### Changed
7
+ ### Deprecated
8
+ ### Removed
9
+ ### Fixed
10
+ ### Security
11
+
12
+ ## [2.2.0]
13
+ ### Added
14
+ - Added Point-In-Time API ([#136](https://github.com/opensearch-project/opensearch-ruby/issues/136))
15
+ ### Changed
16
+ ### Deprecated
17
+ ### Removed
18
+ - Removed Legacy X-Pack Point-In-Time API ([#136](https://github.com/opensearch-project/opensearch-ruby/issues/136))
19
+ ### Fixed
20
+ ### Security
21
+
22
+ ## 2.1.0
23
+ ### Changed
24
+ - Update comments around deprecated and inclusive naming ([#112](https://github.com/opensearch-project/opensearch-ruby/pull/112))
25
+ ### Removed
26
+ - Remove deprecated escape_utils ([#74](https://github.com/opensearch-project/opensearch-ruby/pull/74))
27
+ ### Fixed
28
+ - Fixing tests related to escape utils latest version ([#73](https://github.com/opensearch-project/opensearch-ruby/pull/73))
data/Gemfile CHANGED
@@ -33,8 +33,8 @@ if File.exist? File.expand_path("../../opensearch-transport", __FILE__)
33
33
  gem 'opensearch-transport', path: File.expand_path("../../opensearch-transport", __FILE__), require: true
34
34
  end
35
35
 
36
- if File.exist? File.expand_path("../../opensearch/opensearch.gemspec", __FILE__)
37
- gem 'opensearch-ruby', path: File.expand_path("../../opensearch", __FILE__), require: false
36
+ if File.exist? File.expand_path("../../opensearch-ruby/opensearch-ruby.gemspec", __FILE__)
37
+ gem 'opensearch-ruby', path: File.expand_path("../../opensearch-ruby", __FILE__), require: false
38
38
  end
39
39
 
40
40
  group :development do
data/README.md CHANGED
@@ -1,193 +1,23 @@
1
- # OpenSearch::API
2
-
3
- **This library is part of the [`opensearch-ruby`](https://github.com/opensearch-project/opensearch-ruby/) package;
4
- please refer to it, unless you want to use this library standalone.**
5
-
6
- ----
7
-
8
- The `opensearch-api` library provides a Ruby implementation of
9
- the [OpenSearch](http://opensearch.com) REST API.
10
-
11
- It does not provide an OpenSearch client; see the
12
- [`opensearch-transport`](https://github.com/opensearch-project/opensearch-ruby/tree/main/opensearch-transport) library.
13
-
14
- The library is compatible with Ruby 1.9 and higher.
15
-
16
- It is compatible with OpenSearch's API versions from 1.0.0 till current.
17
-
18
- ## Installation
19
-
20
- Install the package from [Rubygems](https://rubygems.org):
21
-
22
- gem install opensearch-api
23
-
24
- To use an unreleased version, either add it to your `Gemfile` for [Bundler](http://gembundler.com):
25
-
26
- gem 'opensearch-api', git: 'git://github.com/opensearch-project/opensearch-ruby.git'
27
-
28
- or install it from a source code checkout:
29
-
30
- git clone https://github.com/opensearch-project/opensearch-ruby
31
- cd opensearch-ruby/opensearch-api
32
- bundle install
33
- rake install
34
-
35
- ## Usage
36
-
37
- The library is designed as a group of standalone Ruby modules, which can be mixed into a class
38
- providing connection to OpenSearch -- an OpenSearch client.
39
-
40
- ### Usage with the `opensearch` gem
41
-
42
- **When you use the client from the [`opensearch-ruby`](https://github.com/opensearch-project/opensearch-ruby/) package,
43
- the library modules have been already included**, so you just call the API methods:
44
-
45
- ```ruby
46
- require 'opensearch'
47
-
48
- client = OpenSearch::Client.new(log: true)
49
-
50
- client.index(index: 'myindex', id: 1, body: { title: 'Test' })
51
- # => {"_index"=>"myindex", ... "created"=>true}
52
-
53
- client.search(index: 'myindex', body: { query: { match: { title: 'test' } } })
54
- # => {"took"=>2, ..., "hits"=>{"total":5, ...}}
55
- ```
56
-
57
- ### Usage with a custom client
58
-
59
- When you want to mix the library into your own client, it must conform to a following _contract_:
60
-
61
- * It responds to a `perform_request(method, path, params, body, headers)` method,
62
- * the method returns an object with `status`, `body` and `headers` methods.
1
+ - [OpenSearch::API](#opensearchapi)
2
+ - [Compatibility](#compatibility)
3
+ - [User Guide](#user-guide)
4
+ - [License](#license)
63
5
 
64
- A simple client could look like this (_with a dependency on `active_support` to parse the query params_):
65
-
66
- ```ruby
67
- require 'multi_json'
68
- require 'faraday'
69
- require 'opensearch/api'
70
- require 'active_support'
71
-
72
- class MySimpleClient
73
- include OpenSearch::API
74
-
75
- CONNECTION = ::Faraday::Connection.new url: 'http://localhost:9200'
76
-
77
- def perform_request(method, path, params, body, headers = nil)
78
- puts "--> #{method.upcase} #{path} #{params} #{body} #{headers}"
79
-
80
- CONNECTION.run_request \
81
- method.downcase.to_sym,
82
- path_with_params(path, params),
83
- ( body ? MultiJson.dump(body): nil ),
84
- {'Content-Type' => 'application/json'}
85
- end
86
-
87
- private
88
-
89
- def path_with_params(path, params)
90
- return path if params.blank?
91
-
92
- case params
93
- when String
94
- "#{path}?#{params}"
95
- when Hash
96
- "#{path}?#{params.to_query}"
97
- else
98
- raise ArgumentError, "Cannot parse params: '#{params}'"
99
- end
100
- end
101
- end
102
-
103
- client = MySimpleClient.new
104
-
105
- p client.cluster.health
106
- # --> GET _cluster/health {}
107
- # => "{"cluster_name":"opensearch" ... }"
108
-
109
- p client.index index: 'myindex', id: 'custom', body: { title: "Indexing from my client" }
110
- # --> PUT myindex/mytype/custom {} {:title=>"Indexing from my client"}
111
- # => "{"ok":true, ... }"
112
- ```
113
-
114
- ### Using JSON Builders
115
-
116
- Instead of passing the `:body` argument as a Ruby _Hash_, you can pass it as a _String_, potentially
117
- taking advantage of JSON builders such as [JBuilder](https://github.com/rails/jbuilder) or
118
- [Jsonify](https://github.com/bsiggelkow/jsonify):
119
-
120
- ```ruby
121
- require 'jbuilder'
122
-
123
- query = Jbuilder.encode do |json|
124
- json.query do
125
- json.match do
126
- json.title do
127
- json.query 'test 1'
128
- json.operator 'and'
129
- end
130
- end
131
- end
132
- end
133
-
134
- client.search index: 'myindex', body: query
135
-
136
- # 2013-06-25 09:56:05 +0200: GET http://localhost:9200/myindex/_search [status:200, request:0.015s, query:0.011s]
137
- # 2013-06-25 09:56:05 +0200: > {"query":{"match":{"title":{"query":"test 1","operator":"and"}}}}
138
- # ...
139
- # => {"took"=>21, ..., "hits"=>{"total"=>1, "hits"=>[{ "_source"=>{"title"=>"Test 1", ...}}]}}
140
- ```
141
-
142
- ### Using Hash Wrappers
143
-
144
- For a more comfortable access to response properties, you may wrap it in one of the _Hash_ "object access"
145
- wrappers, such as [`Hashie::Mash`](https://github.com/intridea/hashie):
146
-
147
- ```ruby
148
- require 'hashie'
149
-
150
- response = client.search index: 'myindex',
151
- body: {
152
- query: { match: { title: 'test' } },
153
- aggregations: { tags: { terms: { field: 'tags' } } }
154
- }
155
-
156
- mash = Hashie::Mash.new response
157
-
158
- mash.hits.hits.first._source.title
159
- # => 'Test'
160
-
161
- mash.aggregations.tags.terms.first
162
- # => #<Hashie::Mash count=3 term="z">
163
- ```
164
-
165
- ### Using a Custom JSON Serializer
166
-
167
- The library uses the [MultiJson](https://rubygems.org/gems/multi_json/) gem by default,
168
- but allows you to set a custom JSON library, provided it uses the standard `load/dump`
169
- interface:
6
+ # OpenSearch::API
170
7
 
171
- ```ruby
172
- OpenSearch::API.settings[:serializer] = JrJackson::Json
173
- OpenSearch::API.serializer.dump({foo: 'bar'})
174
- # => {"foo":"bar"}
175
- ```
8
+ **This library is part of the [`opensearch-ruby`](https://github.com/opensearch-project/opensearch-ruby/) package; please refer to the [USER_GUIDE](../USER_GUIDE.md), unless you want to use this library standalone.**
176
9
 
177
- ## Development
10
+ The `opensearch-api` library provides a Ruby implementation of the OpenSearch REST APIs.
178
11
 
179
- To work on the code, clone and bootstrap the main repository first -- please see instructions in the main [README](../README.md#development).
12
+ It does not provide an OpenSearch client; see the [`opensearch-transport`](https://github.com/opensearch-project/opensearch-ruby/tree/main/opensearch-transport) library.
180
13
 
181
- To run tests, launch a testing cluster -- again, see instructions in the main [README](../README.md#development) -- and use the Rake tasks:
14
+ ## Compatibility
182
15
 
183
- ```
184
- time rake test:unit
185
- time rake test:integration
186
- ```
16
+ See [COMPATIBILITY](../COMPATIBILITY.md).
187
17
 
188
- We run the test suite for OpenSearch's Rest API tests.
18
+ ## User Guide
189
19
 
190
- The `rest_api` needs the test files from OpenSearch. You can run the rake task to download the test artifacts in the root folder of the project. This task needs a running cluster to determine which version and build hash of OpenSearch to use and test against. `TEST_OPENSEARCH_SERVER=http://localhost:9200 rake opensearch:download_artifacts`. This will download the necessary files used for the integration tests to `./tmp`.
20
+ See [USER_GUIDE](USER_GUIDE.md).
191
21
 
192
22
  ## License
193
23
 
data/Rakefile CHANGED
@@ -56,9 +56,9 @@ namespace :test do
56
56
  url = ENV['TEST_CLUSTER_URL'] || ENV['TEST_OPENSEARCH_SERVER']
57
57
  url = "http://localhost:#{ENV['TEST_CLUSTER_PORT'] || 9200}" unless url
58
58
  client = OpenSearch::Client.new :url => url
59
- es_version_info = client.info['version']
60
- version_number = es_version_info['number']
61
- build_hash = es_version_info['build_hash']
59
+ os_version_info = client.info['version']
60
+ version_number = os_version_info['number']
61
+ build_hash = os_version_info['build_hash']
62
62
  rescue Faraday::ConnectionFailed
63
63
  STDERR.puts "[!] Test cluster not running?"
64
64
  exit 1
@@ -88,7 +88,7 @@ namespace :test do
88
88
  filename = 'tmp/artifacts.json'
89
89
  `curl -s <placeholder_opensearch_artifact_url> -o #{filename}`
90
90
 
91
- unless File.exists?("./#{filename}")
91
+ unless File.exist?("./#{filename}")
92
92
  STDERR.puts '[!] Couldn\'t download artifacts file'
93
93
  exit 1
94
94
  end
@@ -105,7 +105,7 @@ namespace :test do
105
105
  puts 'Downloading zip file:'
106
106
  `curl -s #{zip_url} -o tmp/#{filename}`
107
107
 
108
- unless File.exists?("./tmp/#{filename}")
108
+ unless File.exist?("./tmp/#{filename}")
109
109
  STDERR.puts '[!] Couldn\'t download artifact'
110
110
  exit 1
111
111
  end
data/USER_GUIDE.md ADDED
@@ -0,0 +1,155 @@
1
+ - [User Guide](#user-guide)
2
+ - [Installation](#installation)
3
+ - [Usage](#usage)
4
+ - [Usage with a custom client](#usage-with-a-custom-client)
5
+ - [Using JSON Builders](#using-json-builders)
6
+ - [Using Hash Wrappers](#using-hash-wrappers)
7
+ - [Using a Custom JSON Serializer](#using-a-custom-json-serializer)
8
+ - [Development](#development)
9
+
10
+ # User Guide
11
+ ## Installation
12
+
13
+ To add the gem to your project, install it using [RubyGems](https://rubygems.org/):
14
+
15
+ ```
16
+ gem install opensearch-api
17
+ ```
18
+
19
+ or add it to your Gemfile:
20
+ ```
21
+ gem opensearch-api
22
+ ```
23
+ and run:
24
+ ```
25
+ bundle install
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ The library is designed as a group of standalone Ruby modules, which can be mixed into a class providing connection to OpenSearch -- an OpenSearch client.
31
+
32
+ ### Usage with a custom client
33
+
34
+ To use the library with a custom client, it must conform to a following _contract_:
35
+
36
+ * It responds to a `perform_request(method, path, params, body, headers)` method.
37
+ * The method returns an object with `status`, `body` and `headers` methods.
38
+
39
+ A simple client could look like this (_with a dependency on `active_support` to parse the query params_):
40
+
41
+ ```ruby
42
+ require 'multi_json'
43
+ require 'faraday'
44
+ require 'opensearch/api'
45
+ require 'active_support'
46
+
47
+ class MySimpleClient
48
+ include OpenSearch::API
49
+
50
+ CONNECTION = ::Faraday::Connection.new url: 'http://localhost:9200'
51
+
52
+ def perform_request(method, path, params, body, headers = nil)
53
+ puts "--> #{method.upcase} #{path} #{params} #{body} #{headers}"
54
+
55
+ CONNECTION.run_request \
56
+ method.downcase.to_sym,
57
+ path_with_params(path, params),
58
+ ( body ? MultiJson.dump(body): nil ),
59
+ {'Content-Type' => 'application/json'}
60
+ end
61
+
62
+ private
63
+
64
+ def path_with_params(path, params)
65
+ return path if params.blank?
66
+
67
+ case params
68
+ when String
69
+ "#{path}?#{params}"
70
+ when Hash
71
+ "#{path}?#{params.to_query}"
72
+ else
73
+ raise ArgumentError, "Cannot parse params: '#{params}'"
74
+ end
75
+ end
76
+ end
77
+
78
+ client = MySimpleClient.new
79
+
80
+ p client.cluster.health
81
+
82
+ p client.index index: 'myindex', id: 'custom', body: { title: "Indexing from my client" }
83
+ ```
84
+
85
+ ### Using JSON Builders
86
+
87
+ Instead of passing the `:body` argument as a Ruby _Hash_, you can pass it as a _String_, potentially taking advantage of JSON builders such as [JBuilder](https://github.com/rails/jbuilder) or [Jsonify](https://github.com/bsiggelkow/jsonify):
88
+
89
+ ```ruby
90
+ require 'jbuilder'
91
+
92
+ query = Jbuilder.encode do |json|
93
+ json.query do
94
+ json.match do
95
+ json.title do
96
+ json.query 'test 1'
97
+ json.operator 'and'
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ client.search index: 'myindex', body: query
104
+ # 2013-06-25 09:56:05 +0200: GET http://localhost:9200/myindex/_search [status:200, request:0.015s, query:0.011s]
105
+ # 2013-06-25 09:56:05 +0200: > {"query":{"match":{"title":{"query":"test 1","operator":"and"}}}}
106
+ # ...
107
+ # => {"took"=>21, ..., "hits"=>{"total"=>1, "hits"=>[{ "_source"=>{"title"=>"Test 1", ...}}]}}
108
+ ```
109
+
110
+ ### Using Hash Wrappers
111
+
112
+ For a more comfortable access to response properties, you may wrap it in one of the _Hash_ "object access" wrappers, such as [`Hashie::Mash`](https://github.com/intridea/hashie):
113
+
114
+ ```ruby
115
+ require 'hashie'
116
+
117
+ response = client.search index: 'myindex',
118
+ body: {
119
+ query: { match: { title: 'test' } },
120
+ aggregations: { tags: { terms: { field: 'tags' } } }
121
+ }
122
+
123
+ mash = Hashie::Mash.new response
124
+
125
+ mash.hits.hits.first._source.title
126
+ # => 'test'
127
+
128
+ mash.aggregations.tags.terms.first
129
+ # => #<Hashie::Mash count=3 term="z">
130
+ ```
131
+
132
+ ### Using a Custom JSON Serializer
133
+
134
+ The library uses the [MultiJson](https://rubygems.org/gems/multi_json/) gem by default, but allows you to set a custom JSON library, provided it uses the standard `load/dump` interface:
135
+
136
+ ```ruby
137
+ OpenSearch::API.settings[:serializer] = JrJackson::Json
138
+ OpenSearch::API.serializer.dump({foo: 'bar'})
139
+ # => {"foo":"bar"}
140
+ ```
141
+
142
+ ## Development
143
+
144
+ To work on the code, clone and bootstrap the main repository first -- please see instructions in the main [DEVELOPER_GUIDE](../DEVELOPER_GUIDE.md).
145
+
146
+ To run tests:
147
+
148
+ ```
149
+ time rake test:unit
150
+ time rake test:integration
151
+ ```
152
+
153
+ We run the test suite for OpenSearch's Rest API tests.
154
+
155
+ The `rest_api` needs the test files from OpenSearch. You can run the rake task to download the test artifacts in the root folder of the project. This task needs a running cluster to determine which version and build hash of OpenSearch to use and test against. `TEST_OPENSEARCH_SERVER=http://localhost:9200 rake opensearch:download_artifacts`. This will download the necessary files used for the integration tests to `./tmp`.
@@ -0,0 +1,46 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # The OpenSearch Contributors require contributions made to
4
+ # this file be licensed under the Apache-2.0 license or a
5
+ # compatible open source license.
6
+ #
7
+ # Modifications Copyright OpenSearch Contributors. See
8
+ # GitHub history for details.
9
+
10
+ module OpenSearch
11
+ module API
12
+ module Cat
13
+ module Actions
14
+ # Retrieves info of all PIT segments
15
+ #
16
+ # @option arguments [String] :format a short version of the Accept header, e.g. json, yaml
17
+ # @option arguments [List] :h Comma-separated list of column names to display
18
+ # @option arguments [Boolean] :help Return help information
19
+ # @option arguments [List] :s Comma-separated list of column names or column aliases to sort by
20
+ # @option arguments [Boolean] :v Verbose mode. Display column headers
21
+ # @option arguments [Hash] :headers Custom HTTP headers
22
+ def all_pit_segments(arguments = {})
23
+ arguments = arguments.clone
24
+ headers = arguments.delete(:headers) || {}
25
+
26
+
27
+ method = OpenSearch::API::HTTP_GET
28
+ path = '_cat/pit_segments/_all'
29
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
30
+ params[:h] = Utils.__listify(params[:h]) if params[:h]
31
+
32
+ body = nil
33
+ perform_request(method, path, params, body, headers).body
34
+ end
35
+
36
+ ParamsRegistry.register(:all_pit_segments, [
37
+ :format,
38
+ :h,
39
+ :help,
40
+ :s,
41
+ :v
42
+ ].freeze)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -33,8 +33,9 @@ module OpenSearch
33
33
  # @option arguments [List] :node_id A comma-separated list of node IDs or names to limit the returned information
34
34
  # @option arguments [String] :format a short version of the Accept header, e.g. json, yaml
35
35
  # @option arguments [String] :bytes The unit in which to display byte values (options: b, k, kb, m, mb, g, gb, t, tb, p, pb)
36
- # @option arguments [Boolean] :local Return local information, do not retrieve the state from master node (default: false)
37
- # @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
36
+ # @option arguments [Boolean] :local Return local information, do not retrieve the state from cluster_manager node (default: false)
37
+ # @option arguments [Time] :master_timeout (DEPRECATED: use cluster_manager_timeout instead) Explicit operation timeout for connection to master node
38
+ # @option arguments [Time] :cluster_manager_timeout Explicit operation timeout for connection to cluster_manager node
38
39
  # @option arguments [List] :h Comma-separated list of column names to display
39
40
  # @option arguments [Boolean] :help Return help information
40
41
  # @option arguments [List] :s Comma-separated list of column names or column aliases to sort by
@@ -70,6 +71,7 @@ module OpenSearch
70
71
  :bytes,
71
72
  :local,
72
73
  :master_timeout,
74
+ :cluster_manager_timeout,
73
75
  :h,
74
76
  :help,
75
77
  :s,
@@ -0,0 +1,54 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # The OpenSearch Contributors require contributions made to
4
+ # this file be licensed under the Apache-2.0 license or a
5
+ # compatible open source license.
6
+ #
7
+ # Modifications Copyright OpenSearch Contributors. See
8
+ # GitHub history for details.
9
+
10
+ module OpenSearch
11
+ module API
12
+ module Cat
13
+ module Actions
14
+ # Returns information about the cluster_manager node.
15
+ #
16
+ # @option arguments [String] :format a short version of the Accept header, e.g. json, yaml
17
+ # @option arguments [Boolean] :local Return local information, do not retrieve the state from cluster_manager node (default: false)
18
+ # @option arguments [Time] :cluster_manager_timeout Explicit operation timeout for connection to cluster_manager node
19
+ # @option arguments [List] :h Comma-separated list of column names to display
20
+ # @option arguments [Boolean] :help Return help information
21
+ # @option arguments [List] :s Comma-separated list of column names or column aliases to sort by
22
+ # @option arguments [Boolean] :v Verbose mode. Display column headers
23
+ # @option arguments [Hash] :headers Custom HTTP headers
24
+ #
25
+ #
26
+ def cluster_manager(arguments = {})
27
+ headers = arguments.delete(:headers) || {}
28
+
29
+ arguments = arguments.clone
30
+
31
+ method = OpenSearch::API::HTTP_GET
32
+ path = '_cat/cluster_manager'
33
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
34
+
35
+ body = nil
36
+ perform_request(method, path, params, body, headers).body
37
+ end
38
+
39
+ # Register this action with its valid params when the module is loaded.
40
+ #
41
+ # @since 6.2.0
42
+ ParamsRegistry.register(:cluster_manager, %i[
43
+ format
44
+ local
45
+ cluster_manager_timeout
46
+ h
47
+ help
48
+ s
49
+ v
50
+ ].freeze)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -33,8 +33,9 @@ module OpenSearch
33
33
  # @option arguments [List] :index A comma-separated list of index names to limit the returned information
34
34
  # @option arguments [String] :format a short version of the Accept header, e.g. json, yaml
35
35
  # @option arguments [String] :bytes The unit in which to display byte values (options: b, k, kb, m, mb, g, gb, t, tb, p, pb)
36
- # @option arguments [Boolean] :local Return local information, do not retrieve the state from master node (default: false) *Deprecated*
37
- # @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
36
+ # @option arguments [Boolean] :local Return local information, do not retrieve the state from cluster_manager node (default: false)
37
+ # @option arguments [Time] :master_timeout (DEPRECATED: use cluster_manager_timeout instead) Explicit operation timeout for connection to master node
38
+ # @option arguments [Time] :cluster_manager_timeout Explicit operation timeout for connection to cluster_manager node
38
39
  # @option arguments [List] :h Comma-separated list of column names to display
39
40
  # @option arguments [String] :health A health status ("green", "yellow", or "red" to filter only indices matching the specified health status (options: green, yellow, red)
40
41
  # @option arguments [Boolean] :help Return help information
@@ -75,6 +76,7 @@ module OpenSearch
75
76
  :bytes,
76
77
  :local,
77
78
  :master_timeout,
79
+ :cluster_manager_timeout,
78
80
  :h,
79
81
  :health,
80
82
  :help,
@@ -23,7 +23,8 @@
23
23
  # KIND, either express or implied. See the License for the
24
24
  # specific language governing permissions and limitations
25
25
  # under the License.
26
-
26
+
27
+ # @deprecated Please use cluster_manager instead.
27
28
  module OpenSearch
28
29
  module API
29
30
  module Cat
@@ -60,6 +61,7 @@ module OpenSearch
60
61
  :format,
61
62
  :local,
62
63
  :master_timeout,
64
+ :cluster_manager_timeout,
63
65
  :h,
64
66
  :help,
65
67
  :s,
@@ -31,8 +31,9 @@ module OpenSearch
31
31
  # Returns information about custom node attributes.
32
32
  #
33
33
  # @option arguments [String] :format a short version of the Accept header, e.g. json, yaml
34
- # @option arguments [Boolean] :local Return local information, do not retrieve the state from master node (default: false)
35
- # @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
34
+ # @option arguments [Boolean] :local Return local information, do not retrieve the state from cluster_manager node (default: false)
35
+ # @option arguments [Time] :master_timeout (DEPRECATED: use cluster_manager_timeout instead) Explicit operation timeout for connection to master node
36
+ # @option arguments [Time] :cluster_manager_timeout Explicit operation timeout for connection to cluster_manager node
36
37
  # @option arguments [List] :h Comma-separated list of column names to display
37
38
  # @option arguments [Boolean] :help Return help information
38
39
  # @option arguments [List] :s Comma-separated list of column names or column aliases to sort by
@@ -60,6 +61,7 @@ module OpenSearch
60
61
  :format,
61
62
  :local,
62
63
  :master_timeout,
64
+ :cluster_manager_timeout,
63
65
  :h,
64
66
  :help,
65
67
  :s,
@@ -33,8 +33,9 @@ module OpenSearch
33
33
  # @option arguments [String] :bytes The unit in which to display byte values (options: b, k, kb, m, mb, g, gb, t, tb, p, pb)
34
34
  # @option arguments [String] :format a short version of the Accept header, e.g. json, yaml
35
35
  # @option arguments [Boolean] :full_id Return the full node ID instead of the shortened version (default: false)
36
- # @option arguments [Boolean] :local Calculate the selected nodes using the local cluster state rather than the state from master node (default: false) *Deprecated*
37
- # @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
36
+ # @option arguments [Boolean] :local Calculate the selected nodes using the local cluster state rather than the state from cluster_manager node (default: false) *Deprecated*
37
+ # @option arguments [Time] :master_timeout (DEPRECATED: use cluster_manager_timeout instead) Explicit operation timeout for connection to master node
38
+ # @option arguments [Time] :cluster_manager_timeout Explicit operation timeout for connection to cluster_manager node
38
39
  # @option arguments [List] :h Comma-separated list of column names to display
39
40
  # @option arguments [Boolean] :help Return help information
40
41
  # @option arguments [List] :s Comma-separated list of column names or column aliases to sort by
@@ -67,6 +68,7 @@ module OpenSearch
67
68
  :full_id,
68
69
  :local,
69
70
  :master_timeout,
71
+ :cluster_manager_timeout,
70
72
  :h,
71
73
  :help,
72
74
  :s,