Class: Elastomer::VersionSupport
- Inherits:
-
Object
- Object
- Elastomer::VersionSupport
- Defined in:
- lib/elastomer/version_support.rb
Overview
VersionSupport holds methods that (a) encapsulate version differences; or (b) give an intention-revealing name to a conditional check.
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#delete_by_query_method ⇒ Object
COMPATIBILITY Return a symbol representing the best supported delete_by_query implementation for this version of Elasticsearch.
-
#es_version_2_x? ⇒ Boolean
Elasticsearch 2.0 changed some request formats in a non-backward-compatible way.
-
#es_version_5_x? ⇒ Boolean
(also: #strict_request_params?, #native_delete_by_query?)
Elasticsearch 5.0 changed some request formats in a non-backward-compatible way.
-
#fix_op_type!(params = {}) ⇒ Object
COMPATIBILITY Internal: VersionSupport maintains dynamically-created lists of acceptable and unacceptable request params by ES version.
-
#initialize(version) ⇒ VersionSupport
constructor
version - an Elasticsearch version string e.g., 2.3.5 or 5.3.0.
-
#keyword(**args) ⇒ Object
COMPATIBILITY: Return a “keyword”-type mapping for a field.
-
#op_type(params = {}) ⇒ Object
COMPATIBILITY: handle _op_type -> op_type request param conversion for put-if-absent bnehavior Returns the (possibly mutated) params hash supplied by the caller.
-
#percolator_type ⇒ Object
Wraps version check and param gen where ES version >= 5.x requires percolator type + field defined in mappings.
-
#query_parse_exception ⇒ Object
COMPATIBILITY ES 2.x reports query parsing exceptions as query_parse_exception whereas ES 5.x reports them as query_shard_exception or parsing_exception depending on when the error occurs.
-
#strict_boolean(b) ⇒ Object
COMPATIBILITY: return a simple boolean value or legacy true/false.
-
#supports_gzip? ⇒ Boolean
ES 5.X supports GZip-compressed request bodies, but ES 2.4 doesn’t?.
-
#supports_parent_task_id? ⇒ Boolean
COMPATIBILITY: Return a boolean indicating if this version supports the ‘parent_task_id` param in the tasks API - www.elastic.co/guide/en/elasticsearch/reference/5.x/tasks.html.
-
#supports_tasks_get? ⇒ Boolean
COMPATIBILITY: Return a boolean indicating if this version supports the ‘tasks.get` API - www.elastic.co/guide/en/elasticsearch/reference/5.x/tasks.html.
-
#supports_warmers? ⇒ Boolean
COMPATIBILITY: Return a boolean indicating if this version supports warmers.
-
#tasks_new_response_format? ⇒ Boolean
COMPATIBILITY: The Tasks API is evolving quickly; features, and request/response structure can differ across ES versions.
-
#text(**args) ⇒ Object
COMPATIBILITY: Return a “text”-type mapping for a field.
Constructor Details
#initialize(version) ⇒ VersionSupport
version - an Elasticsearch version string e.g., 2.3.5 or 5.3.0
Raises ArgumentError if version is unsupported.
11 12 13 14 15 16 17 |
# File 'lib/elastomer/version_support.rb', line 11 def initialize(version) if version < "2.3" || version >= "5.7" raise ArgumentError, "Elasticsearch version #{version} is not supported by elastomer-client" end @version = version end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
6 7 8 |
# File 'lib/elastomer/version_support.rb', line 6 def version @version end |
Instance Method Details
#delete_by_query_method ⇒ Object
COMPATIBILITY Return a symbol representing the best supported delete_by_query implementation for this version of Elasticsearch.
156 157 158 159 160 161 162 |
# File 'lib/elastomer/version_support.rb', line 156 def delete_by_query_method if es_version_2_x? :app_delete_by_query else :native_delete_by_query end end |
#es_version_2_x? ⇒ Boolean
Elasticsearch 2.0 changed some request formats in a non-backward-compatible way. Some tests need to know what version is running to structure requests as expected.
Returns true if Elasticsearch version is 2.x.
97 98 99 |
# File 'lib/elastomer/version_support.rb', line 97 def es_version_2_x? version >= "2.0.0" && version < "3.0.0" end |
#es_version_5_x? ⇒ Boolean Also known as: strict_request_params?, native_delete_by_query?
Elasticsearch 5.0 changed some request formats in a non-backward-compatible way. Some tests need to know what version is running to structure requests as expected.
Returns true if Elasticsearch version is 5.x.
106 107 108 |
# File 'lib/elastomer/version_support.rb', line 106 def es_version_5_x? version >= "5.0.0" && version < "6.0.0" end |
#fix_op_type!(params = {}) ⇒ Object
COMPATIBILITY Internal: VersionSupport maintains dynamically-created lists of acceptable and unacceptable request params by ES version. This just shims that list since those params have leading underscores by default. If we end up with >1 such param, let’s make a real thing to handle this.
147 148 149 150 151 |
# File 'lib/elastomer/version_support.rb', line 147 def fix_op_type!(params = {}) if es_version_5_x? && params.key?(:op_type) params[:op_type] = "op_type" end end |
#keyword(**args) ⇒ Object
COMPATIBILITY: Return a “keyword”-type mapping for a field.
On ES 2.x, this will be a string field with not_analyzed=true. On ES 5+, it will be a keyword field.
60 61 62 63 64 65 66 67 68 |
# File 'lib/elastomer/version_support.rb', line 60 def keyword(**args) reject_args!(args, :type, :index) if es_version_2_x? {type: "string", index: "not_analyzed"}.merge(args) else {type: "keyword"}.merge(args) end end |
#op_type(params = {}) ⇒ Object
COMPATIBILITY: handle _op_type -> op_type request param conversion for put-if-absent bnehavior Returns the (possibly mutated) params hash supplied by the caller.
www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#operation-type
85 86 87 88 89 90 |
# File 'lib/elastomer/version_support.rb', line 85 def op_type(params = {}) if es_version_5_x? && (params.key?(:_op_type) || params.key?("_op_type")) params[:op_type] = params.delete(:_op_type) end params end |
#percolator_type ⇒ Object
Wraps version check and param gen where ES version >= 5.x requires percolator type + field defined in mappings
112 113 114 115 116 117 118 |
# File 'lib/elastomer/version_support.rb', line 112 def percolator_type if es_version_5_x? "percolator" else ".percolator" end end |
#query_parse_exception ⇒ Object
COMPATIBILITY ES 2.x reports query parsing exceptions as query_parse_exception whereas ES 5.x reports them as query_shard_exception or parsing_exception depending on when the error occurs.
Returns an Array of Strings to match.
126 127 128 129 130 131 132 |
# File 'lib/elastomer/version_support.rb', line 126 def query_parse_exception if es_version_2_x? ["query_parsing_exception"] else ["query_shard_exception", "parsing_exception"] end end |
#strict_boolean(b) ⇒ Object
COMPATIBILITY: return a simple boolean value or legacy true/false.
73 74 75 76 77 78 79 |
# File 'lib/elastomer/version_support.rb', line 73 def strict_boolean(b) if es_version_2_x? {enabled: b} else b end end |
#supports_gzip? ⇒ Boolean
ES 5.X supports GZip-compressed request bodies, but ES 2.4 doesn’t?
165 166 167 |
# File 'lib/elastomer/version_support.rb', line 165 def supports_gzip? es_version_5_x? end |
#supports_parent_task_id? ⇒ Boolean
COMPATIBILITY: Return a boolean indicating if this version supports the ‘parent_task_id` param in the tasks API - www.elastic.co/guide/en/elasticsearch/reference/5.x/tasks.html
39 40 41 |
# File 'lib/elastomer/version_support.rb', line 39 def supports_parent_task_id? es_version_5_x? end |
#supports_tasks_get? ⇒ Boolean
COMPATIBILITY: Return a boolean indicating if this version supports the ‘tasks.get` API - www.elastic.co/guide/en/elasticsearch/reference/5.x/tasks.html
33 34 35 |
# File 'lib/elastomer/version_support.rb', line 33 def supports_tasks_get? es_version_5_x? end |
#supports_warmers? ⇒ Boolean
COMPATIBILITY: Return a boolean indicating if this version supports warmers. Warmers were removed in ES 5.0.
21 22 23 |
# File 'lib/elastomer/version_support.rb', line 21 def supports_warmers? es_version_2_x? end |
#tasks_new_response_format? ⇒ Boolean
COMPATIBILITY: The Tasks API is evolving quickly; features, and request/response structure can differ across ES versions
27 28 29 |
# File 'lib/elastomer/version_support.rb', line 27 def tasks_new_response_format? es_version_5_x? end |
#text(**args) ⇒ Object
COMPATIBILITY: Return a “text”-type mapping for a field.
On ES 2.x, this will be a string field. On ES 5+, it will be a text field.
46 47 48 49 50 51 52 53 54 |
# File 'lib/elastomer/version_support.rb', line 46 def text(**args) reject_args!(args, :type, :index) if es_version_2_x? {type: "string"}.merge(args) else {type: "text"}.merge(args) end end |