Class: JayAPI::Elasticsearch::QueryBuilder::QueryClauses::Range
- Inherits:
-
QueryClause
- Object
- QueryClause
- JayAPI::Elasticsearch::QueryBuilder::QueryClauses::Range
- Defined in:
- lib/jay_api/elasticsearch/query_builder/query_clauses/range.rb
Overview
Represents a Range
query in Elasticsearch More information about this type of query can be found here: www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
Constant Summary collapse
- VALID_PARAMS =
%i[gt gte lt lte].freeze
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(params) ⇒ Range
constructor
A new instance of Range.
-
#to_h ⇒ Hash
The Hash that represents this query (in Elasticsearch’s format).
Constructor Details
#initialize(params) ⇒ Range
Returns a new instance of Range.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jay_api/elasticsearch/query_builder/query_clauses/range.rb', line 24 def initialize(params) @field = params.delete(:field) || raise(ArgumentError, "Missing required key 'field'") invalid_keys = params.keys - VALID_PARAMS raise ArgumentError, "Invalid keys: #{invalid_keys.join(', ')}" if invalid_keys.any? params = params.compact raise ArgumentError, "At least one of #{VALID_PARAMS.join(', ')} should be given" unless params.any? @params = params end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
15 16 17 |
# File 'lib/jay_api/elasticsearch/query_builder/query_clauses/range.rb', line 15 def field @field end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
15 16 17 |
# File 'lib/jay_api/elasticsearch/query_builder/query_clauses/range.rb', line 15 def params @params end |
Instance Method Details
#to_h ⇒ Hash
Returns The Hash that represents this query (in Elasticsearch’s format).
38 39 40 41 42 43 44 |
# File 'lib/jay_api/elasticsearch/query_builder/query_clauses/range.rb', line 38 def to_h { range: { field => params } } end |