esse 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/esse/cli/event_listener.rb +13 -0
- data/lib/esse/cli/generate.rb +53 -14
- data/lib/esse/cli/index/base_operation.rb +5 -13
- data/lib/esse/cli/index/close.rb +1 -1
- data/lib/esse/cli/index/create.rb +1 -1
- data/lib/esse/cli/index/delete.rb +1 -1
- data/lib/esse/cli/index/import.rb +6 -2
- data/lib/esse/cli/index/open.rb +1 -1
- data/lib/esse/cli/index/reset.rb +1 -1
- data/lib/esse/cli/index/update_aliases.rb +2 -2
- data/lib/esse/cli/index/update_mapping.rb +9 -5
- data/lib/esse/cli/index/update_settings.rb +1 -1
- data/lib/esse/cli/index.rb +11 -4
- data/lib/esse/cli/templates/collection.rb.erb +29 -0
- data/lib/esse/cli/templates/config.rb.erb +13 -3
- data/lib/esse/cli/templates/document.rb.erb +34 -0
- data/lib/esse/cli/templates/index.rb.erb +63 -114
- data/lib/esse/cli/templates/mappings.json +27 -0
- data/lib/esse/cli/templates/settings.json +62 -0
- data/lib/esse/cli.rb +5 -0
- data/lib/esse/cluster.rb +93 -12
- data/lib/esse/cluster_engine.rb +42 -0
- data/lib/esse/collection.rb +18 -0
- data/lib/esse/config.rb +14 -2
- data/lib/esse/core.rb +28 -7
- data/lib/esse/deprecations/cluster.rb +27 -0
- data/lib/esse/deprecations/deprecate.rb +29 -0
- data/lib/esse/deprecations/index.rb +37 -0
- data/lib/esse/deprecations/index_backend_delegator.rb +217 -0
- data/lib/esse/deprecations/repository.rb +34 -0
- data/lib/esse/deprecations/repository_backend_delegator.rb +110 -0
- data/lib/esse/deprecations/serializer.rb +14 -0
- data/lib/esse/deprecations.rb +7 -0
- data/lib/esse/document.rb +91 -0
- data/lib/esse/dynamic_template.rb +43 -0
- data/lib/esse/errors.rb +60 -2
- data/lib/esse/events/event.rb +4 -19
- data/lib/esse/events.rb +13 -2
- data/lib/esse/hash_document.rb +38 -0
- data/lib/esse/import/bulk.rb +106 -0
- data/lib/esse/import/request_body.rb +60 -0
- data/lib/esse/index/aliases.rb +50 -0
- data/lib/esse/index/attributes.rb +107 -0
- data/lib/esse/index/base.rb +17 -53
- data/lib/esse/index/documents.rb +236 -0
- data/lib/esse/index/indices.rb +171 -0
- data/lib/esse/index/inheritance.rb +30 -0
- data/lib/esse/index/mappings.rb +6 -19
- data/lib/esse/index/object_document_mapper.rb +36 -0
- data/lib/esse/index/plugins.rb +42 -0
- data/lib/esse/index/search.rb +27 -0
- data/lib/esse/index/settings.rb +2 -2
- data/lib/esse/index/type.rb +51 -11
- data/lib/esse/index.rb +14 -9
- data/lib/esse/index_mapping.rb +10 -2
- data/lib/esse/index_setting.rb +3 -1
- data/lib/esse/null_document.rb +35 -0
- data/lib/esse/plugins.rb +12 -0
- data/lib/esse/primitives/hstring.rb +1 -1
- data/lib/esse/{index_type → repository}/actions.rb +1 -1
- data/lib/esse/repository/documents.rb +13 -0
- data/lib/esse/repository/object_document_mapper.rb +157 -0
- data/lib/esse/repository.rb +17 -0
- data/lib/esse/search/query.rb +105 -0
- data/lib/esse/search/response.rb +46 -0
- data/lib/esse/template_loader.rb +1 -1
- data/lib/esse/transport/aliases.rb +36 -0
- data/lib/esse/transport/documents.rb +199 -0
- data/lib/esse/transport/health.rb +30 -0
- data/lib/esse/transport/indices.rb +192 -0
- data/lib/esse/transport/search.rb +48 -0
- data/lib/esse/transport.rb +44 -0
- data/lib/esse/version.rb +1 -1
- data/lib/esse.rb +20 -5
- metadata +55 -50
- data/lib/esse/backend/index/aliases.rb +0 -73
- data/lib/esse/backend/index/close.rb +0 -54
- data/lib/esse/backend/index/create.rb +0 -67
- data/lib/esse/backend/index/delete.rb +0 -39
- data/lib/esse/backend/index/documents.rb +0 -23
- data/lib/esse/backend/index/existance.rb +0 -22
- data/lib/esse/backend/index/open.rb +0 -54
- data/lib/esse/backend/index/refresh.rb +0 -43
- data/lib/esse/backend/index/reset.rb +0 -33
- data/lib/esse/backend/index/update.rb +0 -143
- data/lib/esse/backend/index.rb +0 -54
- data/lib/esse/backend/index_type/documents.rb +0 -214
- data/lib/esse/backend/index_type.rb +0 -37
- data/lib/esse/cli/templates/type_collection.rb.erb +0 -41
- data/lib/esse/cli/templates/type_mappings.json +0 -6
- data/lib/esse/cli/templates/type_serializer.rb.erb +0 -23
- data/lib/esse/index/backend.rb +0 -14
- data/lib/esse/index/naming.rb +0 -64
- data/lib/esse/index_type/backend.rb +0 -14
- data/lib/esse/index_type/mappings.rb +0 -42
- data/lib/esse/index_type.rb +0 -15
- data/lib/esse/object_document_mapper.rb +0 -110
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
module Backend
|
5
|
-
class Index
|
6
|
-
module InstanceMethods
|
7
|
-
DEFAULT_OPTIONS = {
|
8
|
-
alias: true,
|
9
|
-
}.freeze
|
10
|
-
|
11
|
-
# Creates index and applies mappings and settings.
|
12
|
-
#
|
13
|
-
# UsersIndex.elasticsearch.create_index # creates index named `<prefix_>users_<suffix|index_version|timestamp>`
|
14
|
-
#
|
15
|
-
# @param options [Hash] Options hash
|
16
|
-
# @option options [Boolean] :alias Update `index_name` alias along with the new index
|
17
|
-
# @option options [String] :suffix The index suffix. Defaults to the `IndexClass#index_version` or
|
18
|
-
# `Esse.timestamp`. Suffixed index names might be used for zero-downtime mapping change.
|
19
|
-
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
20
|
-
#
|
21
|
-
# @see http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/
|
22
|
-
def create_index(suffix: index_version, **options)
|
23
|
-
create_index!(suffix: suffix, **options)
|
24
|
-
rescue Elasticsearch::Transport::Transport::Errors::BadRequest
|
25
|
-
{ 'errors' => true }
|
26
|
-
end
|
27
|
-
|
28
|
-
# Creates index and applies mappings and settings.
|
29
|
-
#
|
30
|
-
# UsersIndex.elasticsearch.create_index! # creates index named `<prefix_>users_<suffix|index_version|timestamp>`
|
31
|
-
#
|
32
|
-
# @param options [Hash] Options hash
|
33
|
-
# @option options [Boolean] :alias Update `index_name` alias along with the new index
|
34
|
-
# @option options [String] :suffix The index suffix. Defaults to the `IndexClass#index_version` or
|
35
|
-
# `Esse.timestamp`. Suffixed index names might be used for zero-downtime mapping change.
|
36
|
-
# @option arguments [String] :wait_for_active_shards Set the number of active shards
|
37
|
-
# to wait for before the operation returns.
|
38
|
-
# @option arguments [Time] :timeout Explicit operation timeout
|
39
|
-
# @option arguments [Time] :master_timeout Specify timeout for connection to master
|
40
|
-
# @option arguments [Hash] :headers Custom HTTP headers
|
41
|
-
# @option arguments [Hash] :body The configuration for the index (`settings` and `mappings`)
|
42
|
-
# @raise [Elasticsearch::Transport::Transport::Errors::NotFound] when index already exists
|
43
|
-
# @return [Hash] the elasticsearch response
|
44
|
-
#
|
45
|
-
# @see http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/
|
46
|
-
def create_index!(suffix: index_version, **options)
|
47
|
-
options = DEFAULT_OPTIONS.merge(options)
|
48
|
-
name = build_real_index_name(suffix)
|
49
|
-
definition = [settings_hash, mappings_hash].reduce(&:merge)
|
50
|
-
|
51
|
-
if options.delete(:alias) && name != index_name
|
52
|
-
definition[:aliases] = { index_name => {} }
|
53
|
-
end
|
54
|
-
|
55
|
-
Esse::Events.instrument('elasticsearch.create_index') do |payload|
|
56
|
-
payload[:request] = opts = options.merge(index: name, body: definition)
|
57
|
-
payload[:response] = response = client.indices.create(**opts)
|
58
|
-
cluster.wait_for_status! if response
|
59
|
-
response
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
include InstanceMethods
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
module Backend
|
5
|
-
class Index
|
6
|
-
module InstanceMethods
|
7
|
-
# Deletes ES index
|
8
|
-
#
|
9
|
-
# UsersIndex.elasticsearch.delete_index! # deletes `<prefix_>users<_suffix|_index_version|_timestamp>` index
|
10
|
-
#
|
11
|
-
# @param suffix [String, nil] The index suffix Use nil if you want to delete the current index.
|
12
|
-
# @raise [Elasticsearch::Transport::Transport::Errors::NotFound] when index does not exists
|
13
|
-
# @return [Hash] elasticsearch response
|
14
|
-
def delete_index!(suffix: index_version, **options)
|
15
|
-
Esse::Events.instrument('elasticsearch.delete_index') do |payload|
|
16
|
-
payload[:request] = opts = options.merge(index: index_name(suffix: suffix))
|
17
|
-
payload[:response] = response = client.indices.delete(**opts)
|
18
|
-
cluster.wait_for_status! if response
|
19
|
-
response
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Deletes ES index
|
24
|
-
#
|
25
|
-
# UsersIndex.elasticsearch.delete_index # deletes `<prefix_>users<_suffix|_index_version|_timestamp>` index
|
26
|
-
#
|
27
|
-
# @param suffix [String, nil] The index suffix Use nil if you want to delete the current index.
|
28
|
-
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
29
|
-
def delete_index(suffix: index_version, **options)
|
30
|
-
delete_index!(suffix: suffix, **options)
|
31
|
-
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
32
|
-
{ 'errors' => true }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
include InstanceMethods
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
module Backend
|
5
|
-
class Index
|
6
|
-
module InstanceMethods
|
7
|
-
def import!(**options)
|
8
|
-
type_hash.each_value do |type|
|
9
|
-
type.elasticsearch.import!(**options)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def import(**options)
|
14
|
-
type_hash.each_value do |type|
|
15
|
-
type.elasticsearch.import(**options)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
include InstanceMethods
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
module Backend
|
5
|
-
class Index
|
6
|
-
module InstanceMethods
|
7
|
-
# Checks the index existance. Returns true or false
|
8
|
-
#
|
9
|
-
# UsersIndex.elasticsearch.exist? #=> true
|
10
|
-
#
|
11
|
-
# @param options [Hash] Options hash
|
12
|
-
# @option options [String, nil] :suffix The index suffix. Defaults to the index_version.
|
13
|
-
# Use nil if you want to check existence of the `index_name` index or alias.
|
14
|
-
def exist?(suffix: index_version)
|
15
|
-
client.indices.exists(index: index_name(suffix: suffix))
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
include InstanceMethods
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
module Backend
|
5
|
-
class Index
|
6
|
-
module InstanceMethods
|
7
|
-
# Open a previously closed index
|
8
|
-
#
|
9
|
-
# @option options [String, nil] :suffix The index suffix. Defaults to the index_version.
|
10
|
-
# Use nil if you want to check existence of the `index_name` index or alias.
|
11
|
-
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that
|
12
|
-
# are open, closed or both. (options: open, closed)
|
13
|
-
# @option options [String] :ignore_indices When performed on multiple indices, allows to ignore
|
14
|
-
# `missing` ones (options: none, missing) @until 1.0
|
15
|
-
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
|
16
|
-
# unavailable (missing, closed, etc)
|
17
|
-
# @option options [Time] :timeout Explicit operation timeout
|
18
|
-
# @raise [Elasticsearch::Transport::Transport::Errors::BadRequest, Elasticsearch::Transport::Transport::Errors::NotFound]
|
19
|
-
# in case of failure
|
20
|
-
# @return [Hash] the elasticsearch response
|
21
|
-
#
|
22
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-open.html
|
23
|
-
def open!(suffix: index_version, **options)
|
24
|
-
Esse::Events.instrument('elasticsearch.open') do |payload|
|
25
|
-
payload[:request] = attributes = options.merge(index: index_name(suffix: suffix))
|
26
|
-
payload[:response] = client.indices.open(**attributes)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# Open a previously closed index
|
31
|
-
#
|
32
|
-
# @option options [String, nil] :suffix The index suffix. Defaults to the index_version.
|
33
|
-
# Use nil if you want to check existence of the `index_name` index or alias.
|
34
|
-
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that
|
35
|
-
# are open, closed or both. (options: open, closed)
|
36
|
-
# @option options [String] :ignore_indices When performed on multiple indices, allows to ignore
|
37
|
-
# `missing` ones (options: none, missing) @until 1.0
|
38
|
-
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
|
39
|
-
# unavailable (missing, closed, etc)
|
40
|
-
# @option options [Time] :timeout Explicit operation timeout
|
41
|
-
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
42
|
-
#
|
43
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-open.html
|
44
|
-
def open(suffix: index_version, **options)
|
45
|
-
open!(suffix: suffix, **options)
|
46
|
-
rescue Elasticsearch::Transport::Transport::ServerError
|
47
|
-
{ 'errors' => true }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
include InstanceMethods
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
module Backend
|
5
|
-
class Index
|
6
|
-
module InstanceMethods
|
7
|
-
# Performs the refresh operation in one or more indices.
|
8
|
-
#
|
9
|
-
# @note The refresh operation can adversely affect indexing throughput when used too frequently.
|
10
|
-
# @param :suffix [String, nil] :suffix The index suffix. Defaults to the index_version.
|
11
|
-
# A uniq index name will be generated if one index already exist with the given alias.
|
12
|
-
# @param options [Hash] Options hash
|
13
|
-
# @raise [Elasticsearch::Transport::Transport::Errors::BadRequest, Elasticsearch::Transport::Transport::Errors::NotFound]
|
14
|
-
# in case of failure
|
15
|
-
# @return [Hash] the elasticsearch response
|
16
|
-
#
|
17
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html
|
18
|
-
def refresh!(suffix: index_version, **options)
|
19
|
-
client.indices.refresh(
|
20
|
-
options.merge(index: index_name(suffix: suffix)),
|
21
|
-
)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Performs the refresh operation in one or more indices.
|
25
|
-
#
|
26
|
-
# @note The refresh operation can adversely affect indexing throughput when used too frequently.
|
27
|
-
# @param :suffix [String, nil] :suffix The index suffix. Defaults to the index_version.
|
28
|
-
# A uniq index name will be generated if one index already exist with the given alias.
|
29
|
-
# @param options [Hash] Options hash
|
30
|
-
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
31
|
-
#
|
32
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html
|
33
|
-
def refresh(suffix: index_version, **options)
|
34
|
-
refresh!(suffix: suffix, **options)
|
35
|
-
rescue Elasticsearch::Transport::Transport::ServerError
|
36
|
-
{ 'errors' => true }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
include InstanceMethods
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
module Backend
|
5
|
-
class Index
|
6
|
-
module InstanceMethods
|
7
|
-
# Deletes, creates and imports data to the index. Performs zero-downtime index resetting.
|
8
|
-
#
|
9
|
-
# @option options [String, nil] :suffix The index suffix. Defaults to the index_version.
|
10
|
-
# A uniq index name will be generated if one index already exist with the given alias.
|
11
|
-
# @option options [Time] :timeout Explicit operation timeout
|
12
|
-
# @raise [Elasticsearch::Transport::Transport::Errors::BadRequest, Elasticsearch::Transport::Transport::Errors::NotFound]
|
13
|
-
# in case of failure
|
14
|
-
# @return [Hash] the elasticsearch response
|
15
|
-
#
|
16
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html
|
17
|
-
def reset_index!(suffix: index_version, **options)
|
18
|
-
existing = []
|
19
|
-
suffix ||= Esse.timestamp
|
20
|
-
suffix = Esse.timestamp while exist?(suffix: suffix).tap { |exist| existing << suffix if exist }
|
21
|
-
|
22
|
-
create_index!(**options, suffix: suffix, alias: false)
|
23
|
-
import!(**options, suffix: suffix)
|
24
|
-
update_aliases!(suffix: suffix)
|
25
|
-
existing.each { |_s| delete_index!(**options, suffix: suffix) }
|
26
|
-
true
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
include InstanceMethods
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
module Backend
|
5
|
-
class Index
|
6
|
-
module InstanceMethods
|
7
|
-
# Create or update a mapping
|
8
|
-
#
|
9
|
-
# @option options [String] :type The name of the document type. This field is required for some elasticsearch versions
|
10
|
-
# @option options [Boolean] :ignore_conflicts Specify whether to ignore conflicts while updating the mapping
|
11
|
-
# (default: false)
|
12
|
-
# @option options [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into
|
13
|
-
# no concrete indices. (This includes `_all` string or when no indices have been specified)
|
14
|
-
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that
|
15
|
-
# are open, closed or both. (options: open, closed)
|
16
|
-
# @option options [String] :ignore_indices When performed on multiple indices, allows to ignore
|
17
|
-
# `missing` ones (options: none, missing) @until 1.0
|
18
|
-
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
|
19
|
-
# unavailable (missing, closed, etc)
|
20
|
-
# @option options [Boolean] :update_all_types Whether to update the mapping for all fields
|
21
|
-
# with the same name across all types
|
22
|
-
# @option options [Time] :timeout Explicit operation timeout
|
23
|
-
# @option options [Boolean] :master_timeout Timeout for connection to master
|
24
|
-
# @raise [Elasticsearch::Transport::Transport::Errors::BadRequest, Elasticsearch::Transport::Transport::Errors::NotFound]
|
25
|
-
# in case of failure
|
26
|
-
# @return [Hash] the elasticsearch response
|
27
|
-
#
|
28
|
-
# @see http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/
|
29
|
-
def update_mapping!(suffix: index_version, **options)
|
30
|
-
Esse::Events.instrument('elasticsearch.update_mapping') do |payload|
|
31
|
-
body = mappings_hash.fetch(Esse::MAPPING_ROOT_KEY)
|
32
|
-
if (type = options[:type])
|
33
|
-
body = body[type.to_s] || body[type.to_sym]
|
34
|
-
end
|
35
|
-
payload[:request] = opts = options.merge(index: index_name(suffix: suffix), body: body)
|
36
|
-
payload[:response] = client.indices.put_mapping(**opts)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# Create or update a mapping
|
41
|
-
#
|
42
|
-
# @option options [String] :type The name of the document type. This field is required for some elasticsearch versions
|
43
|
-
# @option options [Boolean] :ignore_conflicts Specify whether to ignore conflicts while updating the mapping
|
44
|
-
# (default: false)
|
45
|
-
# @option options [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into
|
46
|
-
# no concrete indices. (This includes `_all` string or when no indices have been specified)
|
47
|
-
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that
|
48
|
-
# are open, closed or both. (options: open, closed)
|
49
|
-
# @option options [String] :ignore_indices When performed on multiple indices, allows to ignore
|
50
|
-
# `missing` ones (options: none, missing) @until 1.0
|
51
|
-
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
|
52
|
-
# unavailable (missing, closed, etc)
|
53
|
-
# @option options [Boolean] :update_all_types Whether to update the mapping for all fields
|
54
|
-
# with the same name across all types
|
55
|
-
# @option options [Time] :timeout Explicit operation timeout
|
56
|
-
# @option options [Boolean] :master_timeout Timeout for connection to master
|
57
|
-
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
58
|
-
#
|
59
|
-
# @see http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/
|
60
|
-
def update_mapping(suffix: index_version, **options)
|
61
|
-
update_mapping!(suffix: suffix, **options)
|
62
|
-
rescue Elasticsearch::Transport::Transport::ServerError
|
63
|
-
{ 'errors' => true }
|
64
|
-
end
|
65
|
-
|
66
|
-
# Closes the index for read/write operations, updates the index settings, and open it again
|
67
|
-
#
|
68
|
-
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that
|
69
|
-
# are open, closed or both. (options: open, closed)
|
70
|
-
# @option options [String] :ignore_indices When performed on multiple indices, allows to ignore
|
71
|
-
# `missing` ones (options: none, missing) @until 1.0
|
72
|
-
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
|
73
|
-
# unavailable (missing, closed, etc)
|
74
|
-
# @option options [Boolean] :include_defaults Whether to return all default clusters setting
|
75
|
-
# @option options [Boolean] :preserve_existing Whether to update existing settings.
|
76
|
-
# If set to `true` existing settings on an index remain unchanged, the default is `false`
|
77
|
-
# @option options [Time] :master_timeout Specify timeout for connection to master
|
78
|
-
# @option options [Boolean] :flat_settings Return settings in flat format (default: false)
|
79
|
-
# @raise [Elasticsearch::Transport::Transport::Errors::BadRequest, Elasticsearch::Transport::Transport::Errors::NotFound]
|
80
|
-
# in case of failure
|
81
|
-
# @return [Hash] the elasticsearch response
|
82
|
-
#
|
83
|
-
# @see http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings/
|
84
|
-
def update_settings!(suffix: index_version, **options)
|
85
|
-
response = nil
|
86
|
-
|
87
|
-
settings = settings_hash.fetch(Esse::SETTING_ROOT_KEY).transform_keys(&:to_s)
|
88
|
-
settings.delete('number_of_shards') # Can't change number of shards for an index
|
89
|
-
analysis = settings.delete('analysis')
|
90
|
-
|
91
|
-
if settings.any?
|
92
|
-
# When changing the number of replicas the index needs to be open. Changing the number of replicas on a
|
93
|
-
# closed index might prevent the index to be opened correctly again.
|
94
|
-
Esse::Events.instrument('elasticsearch.update_settings') do |payload|
|
95
|
-
payload[:request] = opts = options.merge(index: index_name(suffix: suffix), body: { index: settings })
|
96
|
-
payload[:response] = response = client.indices.put_settings(**opts)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
if analysis
|
101
|
-
# It is also possible to define new analyzers for the index. But it is required to close the
|
102
|
-
# index first and open it after the changes are made.
|
103
|
-
close!(suffix: suffix)
|
104
|
-
begin
|
105
|
-
Esse::Events.instrument('elasticsearch.update_settings') do |payload|
|
106
|
-
payload[:request] = opts = options.merge(index: index_name(suffix: suffix), body: { analysis: analysis })
|
107
|
-
payload[:response] = response = client.indices.put_settings(**opts)
|
108
|
-
end
|
109
|
-
ensure
|
110
|
-
open!(suffix: suffix)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
response
|
115
|
-
end
|
116
|
-
|
117
|
-
# Closes the index for read/write operations, updates the index settings, and open it again
|
118
|
-
#
|
119
|
-
# @option options [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that
|
120
|
-
# are open, closed or both. (options: open, closed)
|
121
|
-
# @option options [String] :ignore_indices When performed on multiple indices, allows to ignore
|
122
|
-
# `missing` ones (options: none, missing) @until 1.0
|
123
|
-
# @option options [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
|
124
|
-
# unavailable (missing, closed, etc)
|
125
|
-
# @option options [Boolean] :include_defaults Whether to return all default clusters setting
|
126
|
-
# @option options [Boolean] :preserve_existing Whether to update existing settings.
|
127
|
-
# If set to `true` existing settings on an index remain unchanged, the default is `false`
|
128
|
-
# @option options [Time] :master_timeout Specify timeout for connection to master
|
129
|
-
# @option options [Boolean] :flat_settings Return settings in flat format (default: false)
|
130
|
-
# @return [Hash] the elasticsearch response, or an hash with 'errors' as true in case of failure
|
131
|
-
#
|
132
|
-
# @see http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings/
|
133
|
-
def update_settings(suffix: index_version, **options)
|
134
|
-
update_settings!(suffix: suffix, **options)
|
135
|
-
rescue Elasticsearch::Transport::Transport::ServerError
|
136
|
-
{ 'errors' => true }
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
include InstanceMethods
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
data/lib/esse/backend/index.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'forwardable'
|
4
|
-
|
5
|
-
module Esse
|
6
|
-
module Backend
|
7
|
-
class Index
|
8
|
-
require_relative 'index/aliases'
|
9
|
-
require_relative 'index/create'
|
10
|
-
require_relative 'index/delete'
|
11
|
-
require_relative 'index/existance'
|
12
|
-
require_relative 'index/update'
|
13
|
-
require_relative 'index/refresh'
|
14
|
-
require_relative 'index/reset'
|
15
|
-
require_relative 'index/documents'
|
16
|
-
require_relative 'index/open'
|
17
|
-
require_relative 'index/close'
|
18
|
-
|
19
|
-
extend Forwardable
|
20
|
-
|
21
|
-
NAMING = %i[index_version].freeze
|
22
|
-
DEFINITION = %i[settings_hash mappings_hash].freeze
|
23
|
-
|
24
|
-
def_delegators :@index, :type_hash, *(NAMING + DEFINITION)
|
25
|
-
|
26
|
-
def initialize(index)
|
27
|
-
@index = index
|
28
|
-
end
|
29
|
-
|
30
|
-
protected
|
31
|
-
|
32
|
-
def index_name(suffix: nil)
|
33
|
-
suffix = Hstring.new(suffix).underscore.presence
|
34
|
-
return @index.index_name unless suffix
|
35
|
-
|
36
|
-
[@index.index_name, suffix].join('_')
|
37
|
-
end
|
38
|
-
|
39
|
-
def build_real_index_name(suffix = nil)
|
40
|
-
suffix = Hstring.new(suffix).underscore.presence || index_version || Esse.timestamp
|
41
|
-
|
42
|
-
index_name(suffix: suffix)
|
43
|
-
end
|
44
|
-
|
45
|
-
def client
|
46
|
-
cluster.client
|
47
|
-
end
|
48
|
-
|
49
|
-
def cluster
|
50
|
-
@index.cluster
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|