opensearch-api 1.0.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) 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/benchmark.rb +0 -1
  10. data/lib/opensearch/api/actions/bulk.rb +1 -7
  11. data/lib/opensearch/api/actions/cat/all_pit_segments.rb +46 -0
  12. data/lib/opensearch/api/actions/cat/allocation.rb +4 -2
  13. data/lib/opensearch/api/actions/cat/cluster_manager.rb +54 -0
  14. data/lib/opensearch/api/actions/cat/indices.rb +4 -2
  15. data/lib/opensearch/api/actions/cat/master.rb +3 -1
  16. data/lib/opensearch/api/actions/cat/nodeattrs.rb +4 -2
  17. data/lib/opensearch/api/actions/cat/nodes.rb +4 -2
  18. data/lib/opensearch/api/actions/cat/pending_tasks.rb +4 -2
  19. data/lib/opensearch/api/actions/cat/pit_segments.rb +49 -0
  20. data/lib/opensearch/api/actions/cat/plugins.rb +4 -2
  21. data/lib/opensearch/api/actions/cat/repositories.rb +4 -2
  22. data/lib/opensearch/api/actions/cat/shards.rb +4 -2
  23. data/lib/opensearch/api/actions/cat/snapshots.rb +3 -1
  24. data/lib/opensearch/api/actions/cat/templates.rb +4 -2
  25. data/lib/opensearch/api/actions/cat/thread_pool.rb +4 -2
  26. data/lib/opensearch/api/actions/cluster/delete_component_template.rb +4 -2
  27. data/lib/opensearch/api/actions/cluster/exists_component_template.rb +4 -2
  28. data/lib/opensearch/api/actions/cluster/get_component_template.rb +4 -2
  29. data/lib/opensearch/api/actions/cluster/get_settings.rb +3 -1
  30. data/lib/opensearch/api/actions/cluster/health.rb +4 -2
  31. data/lib/opensearch/api/actions/cluster/pending_tasks.rb +5 -3
  32. data/lib/opensearch/api/actions/cluster/put_component_template.rb +4 -2
  33. data/lib/opensearch/api/actions/cluster/put_settings.rb +3 -1
  34. data/lib/opensearch/api/actions/cluster/reroute.rb +4 -2
  35. data/lib/opensearch/api/actions/cluster/state.rb +4 -2
  36. data/lib/opensearch/api/actions/count.rb +1 -6
  37. data/lib/opensearch/api/actions/create.rb +0 -1
  38. data/lib/opensearch/api/actions/create_pit.rb +45 -0
  39. data/lib/opensearch/api/actions/dangling_indices/delete_dangling_index.rb +4 -2
  40. data/lib/opensearch/api/actions/dangling_indices/import_dangling_index.rb +4 -2
  41. data/lib/opensearch/api/actions/delete.rb +1 -8
  42. data/lib/opensearch/api/actions/delete_all_pits.rb +26 -0
  43. data/lib/opensearch/api/actions/delete_by_query.rb +1 -8
  44. data/lib/opensearch/api/actions/delete_pit.rb +30 -0
  45. data/lib/opensearch/api/actions/delete_script.rb +4 -2
  46. data/lib/opensearch/api/actions/exists.rb +1 -8
  47. data/lib/opensearch/api/actions/exists_source.rb +1 -8
  48. data/lib/opensearch/api/actions/explain.rb +1 -8
  49. data/lib/opensearch/api/actions/features/get_features.rb +4 -2
  50. data/lib/opensearch/api/actions/get.rb +1 -8
  51. data/lib/opensearch/api/actions/get_all_pits.rb +26 -0
  52. data/lib/opensearch/api/actions/get_script.rb +4 -2
  53. data/lib/opensearch/api/actions/get_source.rb +1 -8
  54. data/lib/opensearch/api/actions/index.rb +1 -8
  55. data/lib/opensearch/api/actions/indices/add_block.rb +3 -1
  56. data/lib/opensearch/api/actions/indices/clone.rb +3 -1
  57. data/lib/opensearch/api/actions/indices/close.rb +3 -1
  58. data/lib/opensearch/api/actions/indices/create.rb +4 -4
  59. data/lib/opensearch/api/actions/indices/delete.rb +3 -1
  60. data/lib/opensearch/api/actions/indices/delete_alias.rb +4 -2
  61. data/lib/opensearch/api/actions/indices/delete_index_template.rb +4 -2
  62. data/lib/opensearch/api/actions/indices/delete_template.rb +4 -2
  63. data/lib/opensearch/api/actions/indices/exists_index_template.rb +4 -2
  64. data/lib/opensearch/api/actions/indices/exists_template.rb +4 -2
  65. data/lib/opensearch/api/actions/indices/get.rb +4 -4
  66. data/lib/opensearch/api/actions/indices/get_field_mapping.rb +1 -10
  67. data/lib/opensearch/api/actions/indices/get_index_template.rb +4 -2
  68. data/lib/opensearch/api/actions/indices/get_mapping.rb +5 -12
  69. data/lib/opensearch/api/actions/indices/get_settings.rb +3 -1
  70. data/lib/opensearch/api/actions/indices/get_template.rb +4 -4
  71. data/lib/opensearch/api/actions/indices/open.rb +3 -1
  72. data/lib/opensearch/api/actions/indices/put_alias.rb +4 -2
  73. data/lib/opensearch/api/actions/indices/put_index_template.rb +4 -2
  74. data/lib/opensearch/api/actions/indices/put_mapping.rb +4 -13
  75. data/lib/opensearch/api/actions/indices/put_settings.rb +3 -1
  76. data/lib/opensearch/api/actions/indices/put_template.rb +4 -4
  77. data/lib/opensearch/api/actions/indices/rollover.rb +3 -3
  78. data/lib/opensearch/api/actions/indices/shrink.rb +3 -1
  79. data/lib/opensearch/api/actions/indices/simulate_index_template.rb +4 -2
  80. data/lib/opensearch/api/actions/indices/simulate_template.rb +4 -2
  81. data/lib/opensearch/api/actions/indices/split.rb +3 -1
  82. data/lib/opensearch/api/actions/indices/update_aliases.rb +4 -2
  83. data/lib/opensearch/api/actions/indices/validate_query.rb +1 -6
  84. data/lib/opensearch/api/actions/ingest/delete_pipeline.rb +3 -1
  85. data/lib/opensearch/api/actions/ingest/get_pipeline.rb +4 -2
  86. data/lib/opensearch/api/actions/ingest/put_pipeline.rb +3 -1
  87. data/lib/opensearch/api/actions/mget.rb +2 -7
  88. data/lib/opensearch/api/actions/msearch.rb +1 -6
  89. data/lib/opensearch/api/actions/msearch_template.rb +1 -6
  90. data/lib/opensearch/api/actions/mtermvectors.rb +1 -6
  91. data/lib/opensearch/api/actions/put_script.rb +3 -1
  92. data/lib/opensearch/api/actions/search.rb +1 -7
  93. data/lib/opensearch/api/actions/search_shards.rb +1 -1
  94. data/lib/opensearch/api/actions/search_template.rb +1 -6
  95. data/lib/opensearch/api/actions/snapshot/cleanup_repository.rb +3 -1
  96. data/lib/opensearch/api/actions/snapshot/clone.rb +4 -2
  97. data/lib/opensearch/api/actions/snapshot/create.rb +3 -1
  98. data/lib/opensearch/api/actions/snapshot/create_repository.rb +3 -1
  99. data/lib/opensearch/api/actions/snapshot/delete.rb +4 -2
  100. data/lib/opensearch/api/actions/snapshot/delete_repository.rb +3 -1
  101. data/lib/opensearch/api/actions/snapshot/get.rb +3 -1
  102. data/lib/opensearch/api/actions/snapshot/get_features.rb +4 -2
  103. data/lib/opensearch/api/actions/snapshot/get_repository.rb +3 -2
  104. data/lib/opensearch/api/actions/snapshot/restore.rb +3 -1
  105. data/lib/opensearch/api/actions/snapshot/status.rb +3 -1
  106. data/lib/opensearch/api/actions/snapshot/verify_repository.rb +3 -1
  107. data/lib/opensearch/api/actions/termvectors.rb +1 -8
  108. data/lib/opensearch/api/actions/update.rb +1 -8
  109. data/lib/opensearch/api/actions/update_by_query.rb +1 -8
  110. data/lib/opensearch/api/utils.rb +5 -5
  111. data/lib/opensearch/api/version.rb +1 -1
  112. data/lib/opensearch/api.rb +1 -1
  113. data/opensearch-api.gemspec +2 -3
  114. data/spec/opensearch/api/actions/bulk_spec.rb +10 -21
  115. data/spec/opensearch/api/actions/cat/all_pit_segments_spec.rb +36 -0
  116. data/spec/opensearch/api/actions/cat/allocation_spec.rb +6 -7
  117. data/spec/opensearch/api/actions/cat/cluster_manager_spec.rb +26 -0
  118. data/spec/opensearch/api/actions/cat/pit_segments_spec.rb +43 -0
  119. data/spec/opensearch/api/actions/count_spec.rb +3 -3
  120. data/spec/opensearch/api/actions/create_document_spec.rb +8 -8
  121. data/spec/opensearch/api/actions/create_pit_spec.rb +58 -0
  122. data/spec/opensearch/api/actions/delete_all_pits_spec.rb +35 -0
  123. data/spec/opensearch/api/actions/delete_by_query_spec.rb +0 -17
  124. data/spec/opensearch/api/actions/delete_document_spec.rb +10 -10
  125. data/spec/opensearch/api/actions/delete_pit_spec.rb +41 -0
  126. data/spec/opensearch/api/actions/exists_document_spec.rb +10 -10
  127. data/spec/opensearch/api/actions/explain_document_spec.rb +8 -8
  128. data/spec/opensearch/api/actions/get_all_pits_spec.rb +35 -0
  129. data/spec/opensearch/api/actions/get_document_source_spec.rb +6 -6
  130. data/spec/opensearch/api/actions/get_document_spec.rb +8 -8
  131. data/spec/opensearch/api/actions/get_script_spec.rb +2 -2
  132. data/spec/opensearch/api/actions/hashie_spec.rb +0 -2
  133. data/spec/opensearch/api/actions/index_document_spec.rb +12 -12
  134. data/spec/opensearch/api/actions/indices/clone_spec.rb +2 -2
  135. data/spec/opensearch/api/actions/indices/get_field_mapping_spec.rb +0 -11
  136. data/spec/opensearch/api/actions/indices/get_mapping_spec.rb +5 -16
  137. data/spec/opensearch/api/actions/indices/put_mapping_spec.rb +8 -21
  138. data/spec/opensearch/api/actions/indices/validate_query_spec.rb +0 -10
  139. data/spec/opensearch/api/actions/mget_spec.rb +2 -17
  140. data/spec/opensearch/api/actions/mtermvectors_spec.rb +3 -3
  141. data/spec/opensearch/api/actions/search_spec.rb +5 -16
  142. data/spec/opensearch/api/actions/termvectors_spec.rb +5 -5
  143. data/spec/opensearch/api/actions/update_document_spec.rb +11 -11
  144. data/spec/opensearch/api/utils_spec.rb +7 -14
  145. data.tar.gz.sig +0 -0
  146. metadata +40 -43
  147. metadata.gz.sig +0 -0
  148. data/lib/opensearch/api/actions/close_point_in_time.rb +0 -50
  149. data/lib/opensearch/api/actions/indices/exists_type.rb +0 -79
  150. data/lib/opensearch/api/actions/indices/flush_synced.rb +0 -79
  151. data/lib/opensearch/api/actions/open_point_in_time.rb +0 -72
  152. data/spec/opensearch/api/actions/close_point_in_time_spec.rb +0 -43
  153. data/spec/opensearch/api/actions/indices/exists_type_spec.rb +0 -117
  154. data/spec/opensearch/api/actions/indices/flush_synced_spec.rb +0 -99
  155. 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: 0336e67b1234f2806569282b68533fa183b0f26515a163beb4722f578e949a9c
4
- data.tar.gz: 7ea3c280646f1ac0c0f6c78d691da2b488358f68e0fdb1b5bc6938ccc1ca9b6d
3
+ metadata.gz: 832f3792a1ba90a36107ed481ce4a8d312788f0cc6d2499010fbb83f75310b3f
4
+ data.tar.gz: 8cd92be697d977c3e7dbb8e968f89c5e65c72d8780b825db470ae902a0a8fa4e
5
5
  SHA512:
6
- metadata.gz: 551a4da8e0db3d1e8fffda9d6c030838c996d7f95f5a12f457321eb9bf93f95b950511d99dfb9a2ab1fd216a16e87b86daf2a1cbc08891632c37104898b588e7
7
- data.tar.gz: 1fc1d8e8d80319fc4b51f2d0d6977aa3ea4cb93f917b1060959c054507c5e2165c9ca07534e8d31961cb78de6149b844d664c3349137ea1ef40bac1815221e13
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', type: 'mytype', 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', type: 'mytype', 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. You can read more about this in [the test runner README](https://github.com/opensearch-project/opensearch-ruby/tree/main/api-spec-testing#rest-api-yaml-test-runner).
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`.
@@ -65,7 +65,6 @@ module OpenSearch
65
65
  #
66
66
  # @option arguments [List] :index A comma-separated list of index names; use `_all` or empty string
67
67
  # to perform the operation on all indices
68
- # @option arguments [String] :type The name of the document type
69
68
  # @option arguments [Hash] :body The search definition using the Query DSL
70
69
  # @option arguments [Boolean] :verbose Specify whether to return verbose statistics about each iteration
71
70
  # (default: false)
@@ -30,7 +30,6 @@ module OpenSearch
30
30
  # Allows to perform multiple index/update/delete operations in a single request.
31
31
  #
32
32
  # @option arguments [String] :index Default index for items which don't provide one
33
- # @option arguments [String] :type Default document type for items which don't provide one
34
33
  # @option arguments [String] :wait_for_active_shards Sets the number of shard copies that must be active before proceeding with the bulk operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)
35
34
  # @option arguments [String] :refresh If `true` then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes. (options: true, false, wait_for)
36
35
  # @option arguments [String] :routing Specific routing value
@@ -54,12 +53,8 @@ module OpenSearch
54
53
 
55
54
  _index = arguments.delete(:index)
56
55
 
57
- _type = arguments.delete(:type)
58
-
59
56
  method = OpenSearch::API::HTTP_POST
60
- path = if _index && _type
61
- "#{Utils.__listify(_index)}/#{Utils.__listify(_type)}/_bulk"
62
- elsif _index
57
+ path = if _index
63
58
  "#{Utils.__listify(_index)}/_bulk"
64
59
  else
65
60
  "_bulk"
@@ -85,7 +80,6 @@ module OpenSearch
85
80
  :refresh,
86
81
  :routing,
87
82
  :timeout,
88
- :type,
89
83
  :_source,
90
84
  :_source_excludes,
91
85
  :_source_includes,
@@ -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,