Module: Esse::Transport::InstanceMethods
- Included in:
- Esse::Transport
- Defined in:
- lib/esse/transport/health.rb,
lib/esse/transport/search.rb,
lib/esse/transport/aliases.rb,
lib/esse/transport/indices.rb,
lib/esse/transport/documents.rb
Instance Method Summary collapse
-
#aliases(**options) ⇒ Object
Return a list of index aliases.
-
#bulk(body:, **options) ⇒ Object
Allows to perform multiple index/update/delete operations in a single request.
-
#clear_scroll(body:, **options) ⇒ Object
Explicitly clears the search context for a scroll.
-
#close(index:, **options) ⇒ Hash
Close an index (keep the data on disk, but deny operations with the index).
-
#count(index:, **options) ⇒ Object
Returns number of documents matching a query.
-
#create_index(index:, wait_for_status: nil, **options) ⇒ Object
Creates an index with optional settings and mappings.
-
#delete(id:, index:, **options) ⇒ Object
Removes a document from the index.
-
#delete_index(index:, wait_for_status: nil, **options) ⇒ Object
Deletes an index.
-
#exist?(id:, index:, **options) ⇒ Boolean
Returns information about whether a document exists in an index.
-
#get(id:, index:, **options) ⇒ Object
Returns a document.
-
#health(**options) ⇒ Object
Returns basic information about the health of the cluster.
-
#index(id:, index:, body:, **options) ⇒ Object
Creates or updates a document in an index.
-
#index_exist?(index:, **options) ⇒ Boolean
Returns information about whether a particular index exists.
-
#open(index:, **options) ⇒ Hash
Open a previously closed index.
-
#refresh(index:, **options) ⇒ Object
Performs the refresh operation in one or more indices.
-
#reindex(body:, **options) ⇒ Object
Allows to copy documents from one index to another, optionally filtering the source documents by a query, changing the destination index settings, or fetching the documents from a remote cluster.
-
#scroll(scroll:, **definition) ⇒ Object
Allows to retrieve a large numbers of results from a single search request.
-
#search(index:, **options) ⇒ Object
Returns results matching a query.
-
#update(id:, index:, body:, **options) ⇒ Object
Updates a document with a script or partial document.
-
#update_aliases(body:, **options) ⇒ Object
Updates index aliases.
-
#update_by_query(index:, **options) ⇒ Object
Performs an update on every document in the index without changing the source, for example to pick up a mapping change.
-
#update_mapping(index:, body:, **options) ⇒ Object
Updates the index mappings.
-
#update_settings(index:, body:, **options) ⇒ Object
Updates the index settings.
Instance Method Details
#aliases(**options) ⇒ Object
Return a list of index aliases.
14 15 16 |
# File 'lib/esse/transport/aliases.rb', line 14 def aliases(**) coerce_exception { client.indices.get_alias(**) } end |
#bulk(body:, **options) ⇒ Object
Allows to perform multiple index/update/delete operations in a single request.
or the conveniency “combined” format can be passed, refer to Elasticsearch::API::Utils.__bulkify documentation.
185 186 187 188 189 190 191 192 193 194 |
# File 'lib/esse/transport/documents.rb', line 185 def bulk(body:, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.bulk') do |payload| payload[:request] = opts = .merge(body: body) payload[:response] = response = coerce_exception { client.bulk(**opts) } yield(payload) if block_given? # Allow caller to add data to the payload of event response end end |
#clear_scroll(body:, **options) ⇒ Object
Explicitly clears the search context for a scroll.
41 42 43 |
# File 'lib/esse/transport/search.rb', line 41 def clear_scroll(body:, **) coerce_exception { client.clear_scroll(body: body, **) } end |
#close(index:, **options) ⇒ Hash
Close an index (keep the data on disk, but deny operations with the index).
117 118 119 120 121 122 123 124 |
# File 'lib/esse/transport/indices.rb', line 117 def close(index:, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.close') do |payload| payload[:request] = attributes = .merge(index: index) payload[:response] = coerce_exception { client.indices.close(**attributes) } end end |
#count(index:, **options) ⇒ Object
Returns number of documents matching a query.
78 79 80 81 82 83 |
# File 'lib/esse/transport/documents.rb', line 78 def count(index:, **) Esse::Events.instrument('elasticsearch.count') do |payload| payload[:request] = opts = .merge(index: index) payload[:response] = coerce_exception { client.count(**opts) } end end |
#create_index(index:, wait_for_status: nil, **options) ⇒ Object
Creates an index with optional settings and mappings.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/esse/transport/indices.rb', line 18 def create_index(index:, wait_for_status: nil, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.create_index') do |payload| payload[:request] = opts = .merge(index: index) payload[:response] = response = coerce_exception { client.indices.create(**opts) } if response && response['acknowledged'] coerce_exception do cluster.wait_for_status!(status: (wait_for_status || cluster.wait_for_status), index: index) end end response end end |
#delete(id:, index:, **options) ⇒ Object
Removes a document from the index.
100 101 102 103 104 105 106 107 |
# File 'lib/esse/transport/documents.rb', line 100 def delete(id:, index:, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.delete') do |payload| payload[:request] = opts = .merge(id: id, index: index) payload[:response] = coerce_exception { client.delete(**opts) } end end |
#delete_index(index:, wait_for_status: nil, **options) ⇒ Object
Deletes an index.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/esse/transport/indices.rb', line 64 def delete_index(index:, wait_for_status: nil, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.delete_index') do |payload| payload[:request] = opts = .merge(index: index) payload[:response] = response = coerce_exception { client.indices.delete(**opts) } if response && response['acknowledged'] coerce_exception do cluster.wait_for_status!(status: (wait_for_status || cluster.wait_for_status), index: index) end end response end end |
#exist?(id:, index:, **options) ⇒ Boolean
Returns information about whether a document exists in an index.
50 51 52 53 54 55 |
# File 'lib/esse/transport/documents.rb', line 50 def exist?(id:, index:, **) Esse::Events.instrument('elasticsearch.exist') do |payload| payload[:request] = opts = .merge(id: id, index: index) payload[:response] = coerce_exception { client.exists(**opts) } end end |
#get(id:, index:, **options) ⇒ Object
Returns a document.
25 26 27 28 29 30 |
# File 'lib/esse/transport/documents.rb', line 25 def get(id:, index:, **) Esse::Events.instrument('elasticsearch.get') do |payload| payload[:request] = opts = .merge(id: id, index: index) payload[:response] = coerce_exception { client.get(**opts) } end end |
#health(**options) ⇒ Object
Returns basic information about the health of the cluster.
23 24 25 |
# File 'lib/esse/transport/health.rb', line 23 def health(**) coerce_exception { client.cluster.health(**) } end |
#index(id:, index:, body:, **options) ⇒ Object
Creates or updates a document in an index.
158 159 160 161 162 163 164 165 |
# File 'lib/esse/transport/documents.rb', line 158 def index(id:, index:, body:, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.index') do |payload| payload[:request] = opts = .merge(id: id, index: index, body: body) payload[:response] = coerce_exception { client.index(**opts) } end end |
#index_exist?(index:, **options) ⇒ Boolean
Returns information about whether a particular index exists.
45 46 47 48 49 50 |
# File 'lib/esse/transport/indices.rb', line 45 def index_exist?(index:, **) Esse::Events.instrument('elasticsearch.index_exist') do |payload| payload[:request] = opts = .merge(index: index) payload[:response] = coerce_exception { client.indices.exists(**opts) } end end |
#open(index:, **options) ⇒ Hash
Open a previously closed index
94 95 96 97 98 99 100 101 |
# File 'lib/esse/transport/indices.rb', line 94 def open(index:, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.open') do |payload| payload[:request] = attributes = .merge(index: index) payload[:response] = coerce_exception { client.indices.open(**attributes) } end end |
#refresh(index:, **options) ⇒ Object
Performs the refresh operation in one or more indices.
135 136 137 138 139 140 141 142 |
# File 'lib/esse/transport/indices.rb', line 135 def refresh(index:, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.refresh') do |payload| payload[:request] = attributes = .merge(index: index) payload[:response] = coerce_exception { client.indices.refresh(**attributes) } end end |
#reindex(body:, **options) ⇒ Object
Allows to copy documents from one index to another, optionally filtering the source documents by a query, changing the destination index settings, or fetching the documents from a remote cluster.
205 206 207 208 209 210 211 212 |
# File 'lib/esse/transport/indices.rb', line 205 def reindex(body:, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.reindex') do |payload| payload[:request] = opts = .merge(body: body) payload[:response] = coerce_exception { client.reindex(**opts) } end end |
#scroll(scroll:, **definition) ⇒ Object
Allows to retrieve a large numbers of results from a single search request.
26 27 28 29 30 31 32 33 34 |
# File 'lib/esse/transport/search.rb', line 26 def scroll(scroll:, **definition) unless definition[:body] raise ArgumentError, 'scroll search must have a :body with the :scroll_id' end Esse::Events.instrument('elasticsearch.search') do |payload| payload[:request] = definition payload[:response] = coerce_exception { client.scroll(scroll: scroll, **definition) } end end |
#search(index:, **options) ⇒ Object
Returns results matching a query.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/esse/transport/search.rb', line 9 def search(index:, **) definition = .merge( index: index, ) Esse::Events.instrument('elasticsearch.search') do |payload| payload[:request] = definition payload[:response] = coerce_exception { client.search(definition) } end end |
#update(id:, index:, body:, **options) ⇒ Object
Updates a document with a script or partial document.
130 131 132 133 134 135 136 137 |
# File 'lib/esse/transport/documents.rb', line 130 def update(id:, index:, body:, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.update') do |payload| payload[:request] = opts = .merge(id: id, index: index, body: body) payload[:response] = coerce_exception { client.update(**opts) } end end |
#update_aliases(body:, **options) ⇒ Object
Updates index aliases.
24 25 26 27 28 29 30 31 |
# File 'lib/esse/transport/aliases.rb', line 24 def update_aliases(body:, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.update_aliases') do |payload| payload[:request] = .merge(body: body) payload[:response] = coerce_exception { client.indices.update_aliases(**, body: body) } end end |
#update_by_query(index:, **options) ⇒ Object
Performs an update on every document in the index without changing the source, for example to pick up a mapping change.
257 258 259 260 261 262 263 264 |
# File 'lib/esse/transport/indices.rb', line 257 def update_by_query(index:, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.update_by_query') do |payload| payload[:request] = opts = .merge(index: index) payload[:response] = coerce_exception { client.update_by_query(**opts) } end end |
#update_mapping(index:, body:, **options) ⇒ Object
Updates the index mappings.
157 158 159 160 161 162 163 164 |
# File 'lib/esse/transport/indices.rb', line 157 def update_mapping(index:, body:, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.update_mapping') do |payload| payload[:request] = opts = .merge(index: index, body: body) payload[:response] = coerce_exception { client.indices.put_mapping(**opts) } end end |
#update_settings(index:, body:, **options) ⇒ Object
Updates the index settings.
180 181 182 183 184 185 186 187 |
# File 'lib/esse/transport/indices.rb', line 180 def update_settings(index:, body:, **) throw_error_when_readonly! Esse::Events.instrument('elasticsearch.update_settings') do |payload| payload[:request] = opts = .merge(index: index, body: body) payload[:response] = coerce_exception { client.indices.put_settings(**opts) } end end |