Class: JayAPI::Elasticsearch::QueryBuilder::Script

Inherits:
Object
  • Object
show all
Defined in:
lib/jay_api/elasticsearch/query_builder/script.rb

Overview

Represents a scripted element in a query. This scripted element can be used in different places. It can be used in a query clause, but can also be used to create custom aggregations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, lang: 'painless', params: nil) ⇒ Script

Returns a new instance of Script.

Parameters:

  • source (String)

    The source for the script element.

  • lang (String) (defaults to: 'painless')

    The language the script is written in.

  • params (Hash) (defaults to: nil)

    A Hash with key-value pairs for the script’s parameters.



16
17
18
19
20
21
22
23
# File 'lib/jay_api/elasticsearch/query_builder/script.rb', line 16

def initialize(source:, lang: 'painless', params: nil)
  @source = source
  @lang = lang

  # Keeps the parameters from being modified from the outside after the
  # class has been initialized.
  @params = params.dup.freeze
end

Instance Attribute Details

#langObject (readonly)

Returns the value of attribute lang.



10
11
12
# File 'lib/jay_api/elasticsearch/query_builder/script.rb', line 10

def lang
  @lang
end

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/jay_api/elasticsearch/query_builder/script.rb', line 10

def params
  @params
end

#sourceObject (readonly)

Returns the value of attribute source.



10
11
12
# File 'lib/jay_api/elasticsearch/query_builder/script.rb', line 10

def source
  @source
end

Instance Method Details

#to_hHash

Returns The hash representation of the scripted element.

Returns:

  • (Hash)

    The hash representation of the scripted element.



26
27
28
29
30
31
32
# File 'lib/jay_api/elasticsearch/query_builder/script.rb', line 26

def to_h
  {
    source: source,
    lang: lang,
    params: params
  }.compact
end