Class: Elastic::ESQL
- Inherits:
-
Object
- Object
- Elastic::ESQL
- Defined in:
- lib/elastic/esql.rb
Overview
Constant Summary collapse
- SOURCE_COMMANDS =
[:from, :promql, :row, :show, :ts].freeze
Class Method Summary collapse
-
.branch ⇒ Object
rubocop:enable Naming/MethodName, Naming/BinaryOperatorParameterName.
- .chicken ⇒ Object
- .π(message) ⇒ Object
Instance Method Summary collapse
-
#enrich(policy) ⇒ Elastic::Enrich
Creates a new Enrich object to chain with
onandwith. -
#from(index_pattern) ⇒ Object
Instance method to allow to update
fromwith esql.from(βdifferent_sourceβ). -
#initialize ⇒ ESQL
constructor
A new instance of ESQL.
-
#query ⇒ String
Function to build the ES|QL formatted query and return it as a String.
-
#rerank(column: nil, query: '') ⇒ Elastic::Rerank
Creates a new Rerank object to chain with
onandwith. -
#to_s ⇒ Object
Defining to_s so the ES|QL formatted query is returned.
-
#user_agent(params) ⇒ Elastic::UserAgent
Creates a new UserAgent object to chain with
with. - #π(message) ⇒ Object (also: #chicken)
Constructor Details
#initialize ⇒ ESQL
Returns a new instance of ESQL.
64 65 66 67 68 |
# File 'lib/elastic/esql.rb', line 64 def initialize @query = {} @custom = [] @metadata = [] end |
Class Method Details
.branch ⇒ Object
rubocop:enable Naming/MethodName, Naming/BinaryOperatorParameterName
146 147 148 |
# File 'lib/elastic/esql.rb', line 146 def self.branch Branch.new end |
.chicken ⇒ Object
137 138 139 |
# File 'lib/elastic/esql.rb', line 137 def π() "ROW CHICKEN(\"#{}\")" end |
.π(message) ⇒ Object
134 135 136 |
# File 'lib/elastic/esql.rb', line 134 def π() "ROW CHICKEN(\"#{}\")" end |
Instance Method Details
#enrich(policy) ⇒ Elastic::Enrich
Creates a new Enrich object to chain with on and with. If other method is chained to the Enrich object, it calls it upon the ESQL object that instantiated it, and returns it.
104 105 106 107 108 109 |
# File 'lib/elastic/esql.rb', line 104 def enrich(policy) @enriches ||= [] enrich = Enrich.new(policy, self) @enriches << enrich enrich end |
#from(index_pattern) ⇒ Object
Instance method to allow to update from with esql.from(βdifferent_sourceβ).
121 122 123 124 |
# File 'lib/elastic/esql.rb', line 121 def from(index_pattern) @query = { from: index_pattern } self end |
#query ⇒ String
Function to build the ES|QL formatted query and return it as a String.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/elastic/esql.rb', line 90 def query raise ArgumentError, 'No source command found' unless source_command_present? string_query = @set ? "SET #{@set};\n" : '' @query[:enrich] = @enriches.map(&:to_query).join('| ') if @enriches @query[:rerank] = @rerank.to_query if @rerank string_query.concat(build_string_query) string_query.concat(" #{@custom.join(' ')}") unless @custom.empty? string_query end |
#rerank(column: nil, query: '') ⇒ Elastic::Rerank
Creates a new Rerank object to chain with on and with. If other method is chained to the Rerank object, it calls it upon the ESQL object that instantiated it, and returns it.
114 115 116 117 |
# File 'lib/elastic/esql.rb', line 114 def rerank(column: nil, query: '') @rerank = Rerank.new(self, column: column, query: query) @rerank end |
#to_s ⇒ Object
Defining to_s so the ES|QL formatted query is returned. This way the query will be serialized when passing an Elastic::ESQL object to the Elasticsearch client and other libraries.
128 129 130 |
# File 'lib/elastic/esql.rb', line 128 def to_s query end |
#user_agent(params) ⇒ Elastic::UserAgent
Creates a new UserAgent object to chain with with. If other method is chained to the UserAgent object, it calls it upon the ESQL object that instantiated it, and returns it.
153 154 155 |
# File 'lib/elastic/esql.rb', line 153 def user_agent(params) UserAgent.new(params, self) end |
#π(message) ⇒ Object Also known as: chicken
140 141 142 |
# File 'lib/elastic/esql.rb', line 140 def π() self.class.π() end |